Results 1 to 20 of 20

Thread: Macro won't modify style in Word 2003

  1. #1
    New Member
    Join Date
    Jul 12
    Posts
    9

    Macro won't modify style in Word 2003

    I'm trying to make a macro that changes all comment text to left-to-right text. I can do this manually (create comment, change style to automatically update, then apply LTR) but the macro I record doesn't make the change. Indeed, in Word 2003 it doesn't even work while I'm recording the macro.

    Here's the code in Word 2003:

    Code:
        Selection.Comments.Add Range:=Selection.Range
        With ActiveDocument.Styles("Comment Text")
            .AutomaticallyUpdate = True
            .BaseStyle = "Normal"
            .NextParagraphStyle = "Comment Text"
        End With
        Selection.LtrPara
        With ActiveDocument.Styles("Comment Text")
            .AutomaticallyUpdate = False
            .BaseStyle = "Normal"
            .NextParagraphStyle = "Comment Text"
        End With
        WordBasic.RejectChangesSelected
    It doesn't work in Word 2007 either. The code (below) seems to basically boil down to

    Code:
    ActiveDocument.Styles("Comment Text").ParagraphFormat.Alignment = wdAlignParagraphLeft
    Here's 2007's complete code:

    Code:
        Selection.Comments.Add Range:=Selection.Range
        Selection.LtrPara
        WordBasic.FormatStyle Name:="Comment Text", NewName:="", BasedOn:="", _
            NextStyle:="", Type:=0, FileName:="", Link:=""
        With ActiveDocument.Styles("Comment Text").Font
            .Name = "Arial"
            .Size = 10
            .Bold = False
            .Italic = False
            .Underline = wdUnderlineNone
            .UnderlineColor = wdColorAutomatic
            .StrikeThrough = False
            .DoubleStrikeThrough = False
            .Outline = False
            .Emboss = False
            .Shadow = False
            .Hidden = False
            .SmallCaps = False
            .AllCaps = False
            .Color = wdColorAutomatic
            .Engrave = False
            .Superscript = False
            .Subscript = False
            .Scaling = 100
            .Kerning = 0
            .Animation = wdAnimationNone
        End With
        With ActiveDocument.Styles("Comment Text").ParagraphFormat
            .LeftIndent = InchesToPoints(0)
            .RightIndent = InchesToPoints(0)
            .SpaceBefore = 0
            .SpaceBeforeAuto = False
            .SpaceAfter = 10
            .SpaceAfterAuto = False
            .LineSpacingRule = wdLineSpaceSingle
            .Alignment = wdAlignParagraphLeft
            .WidowControl = True
            .KeepWithNext = False
            .KeepTogether = False
            .PageBreakBefore = False
            .NoLineNumber = False
            .Hyphenation = True
            .FirstLineIndent = InchesToPoints(0)
            .OutlineLevel = wdOutlineLevelBodyText
            .CharacterUnitLeftIndent = 0
            .CharacterUnitRightIndent = 0
            .CharacterUnitFirstLineIndent = 0
            .LineUnitBefore = 0
            .LineUnitAfter = 0
            .MirrorIndents = False
            .TextboxTightWrap = wdTightNone
        End With
        ActiveDocument.Styles("Comment Text").NoSpaceBetweenParagraphsOfSameStyle _
            = False
        ActiveDocument.Styles("Comment Text").ParagraphFormat.TabStops.ClearAll
        With ActiveDocument.Styles("Comment Text").ParagraphFormat
            With .Shading
                .Texture = wdTextureNone
                .ForegroundPatternColor = wdColorAutomatic
                .BackgroundPatternColor = wdColorAutomatic
            End With
            .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
            .Borders(wdBorderRight).LineStyle = wdLineStyleNone
            .Borders(wdBorderTop).LineStyle = wdLineStyleNone
            .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
            With .Borders
                .DistanceFromTop = 1
                .DistanceFromLeft = 4
                .DistanceFromBottom = 1
                .DistanceFromRight = 4
                .Shadow = False
            End With
        End With
        ActiveDocument.Styles("Comment Text").LanguageID = wdEnglishUS
        ActiveDocument.Styles("Comment Text").NoProofing = False
        ActiveDocument.Styles("Comment Text").Frame.Delete
    Any thoughts?
    Last edited by koolsid; Jul 20th, 2012 at 02:45 PM. Reason: Added Code Tags

  2. #2
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    Welcome to the forums levydav: wave:

    The reason it is not working for Word 2003 is because of this line

    WordBasic.RejectChangesSelected
    You are making the changes and then rejecting them. Run your code without that line and see if it works
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  3. #3
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    Still doesn't work ...

  4. #4
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    When you run the code, does it create the comment?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  5. #5
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    Yes, though it doesn't apply the LTR, and also leaves me sort of in record macro mode (no mouse clicks in text) - I have to restart to fix it

  6. #6
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    Strange, it not only lets me edit the text but is also left aligned. Please see snapshot.

    Code I used

    Code:
    Sub Sample()
        Selection.Comments.Add Range:=Selection.Range
        With ActiveDocument.Styles("Comment Text")
            .AutomaticallyUpdate = True
            .BaseStyle = "Normal"
            .NextParagraphStyle = "Comment Text"
        End With
        Selection.LtrPara
        With ActiveDocument.Styles("Comment Text")
            .AutomaticallyUpdate = False
            .BaseStyle = "Normal"
            .NextParagraphStyle = "Comment Text"
        End With
    End Sub
    SNAPSHOT
    Attached Images Attached Images  
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  7. #7
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    But not when done on a right-to-left document - try it on the attached one. I don't understand it...
    Attached Files Attached Files

  8. #8
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    This is what I get.
    Attached Images Attached Images  
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  9. #9
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    Yes, same here: the comment is still right-to-left. But if you carry out the steps manually, it (and all subsequent) comments will be left-to-right:

    1. Create new comment (Insert > Comment)
    2. Modify comment style to automatically update (Format > Styles and formatting > down arrow next to Comment Text > Modify... > check Automatically update box > OK)
    3. Format paragraph left-to-right (need to first assign button/key combination to LtrPara: Tools > Customize > Categories: All Commands > Commands: drag LtrPara to toolbar)
    4. Turn off automatically update for Comment Text style
    5. Delete comment

    BTW, the reason why I need to do this is that I get a lot of English documents that were created on Arabic-language computers. The main text is not a problem, but writing English comments in RTL mixes up the word order.

    Thanks

  10. #10
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,520

    Re: Macro won't modify style in Word 2003

    I don't understand it...
    me too, i get an empty document when i open your attachment, no code, no text
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    Pete, You have to use the code from Post 6.

    Type any word in the word document, highlight it and run the code from post 6.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  12. #12
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,520

    Re: Macro won't modify style in Word 2003

    i must have missed the point of posting an empty document to type something into

    a sample document, that demonstrates the problem, would have to of been of more value
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    levydav, I tested it manually as well as with the code but the comment is pretty much readable. Please see this sncreenshot.

    I agree that when you manually type then the words are in reverse order but after typing, if you pause for a moment, the words are automatically rearranged.

    Screenshot
    Attached Images Attached Images  
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  14. #14
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    Try typing a longer sentence, then making a change in the middle of it - it starts to behave strangely and in a way you wouldn't want to deal with if you were writing a hundred comments. This is a regular headache for our editors when working with English documents that were created on Arabic-language computers.

    However, doing these steps manually should fix the problem; but the macro doesn't behave the same as manually...

  15. #15
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    I am sorry, I know how you feel. But I could not find a way to reverse the existing way comment behaves. Would you be interested in an alternative ?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  16. #16
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    The following steps will make all new comments left-to-right:

    1. Create new comment (Insert > Comment)
    2. Modify comment style to automatically update (Format > Styles and formatting > down arrow next to Comment Text > Modify... > check Automatically update box > OK)
    3. Format paragraph left-to-right (need to first assign button/key combination to LtrPara: Tools > Customize > Categories: All Commands > Commands: drag LtrPara to toolbar)
    4. Turn off automatically update for Comment Text style
    5. Delete comment

    But this doesn't work in a macro...

  17. #17
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    Quote Originally Posted by koolsid View Post
    Would you be interested in an alternative ?
    You missed my previous post
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  18. #18
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    I guess I don't understand what you mean by "reverse the existing way comment behaves". Do you have an alternative?

    Thanks,

  19. #19
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,405

    Re: Macro won't modify style in Word 2003

    Why not create a user form which accepts input for comment in a multiline textbox and this userform can be called by a shortcut key? That way the users can type very comfortably in the userform's textbox and when they are done, the update button will update the comment? let me know if you want to see an example?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  20. #20
    New Member
    Join Date
    Jul 12
    Posts
    9

    Re: Macro won't modify style in Word 2003

    Interesting solution. I think at this point, though, I'd rather just do these steps once by hand before handing articles over to the editor. I was just hoping that these steps could be included in the preparation macro that we run on all papers before giving to editors. - Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •