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?
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
Quote:
WordBasic.RejectChangesSelected
You are making the changes and then rejecting them. Run your code without that line and see if it works :)
Re: Macro won't modify style in Word 2003
Re: Macro won't modify style in Word 2003
When you run the code, does it create the comment?
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
1 Attachment(s)
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
1 Attachment(s)
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...
1 Attachment(s)
Re: Macro won't modify style in Word 2003
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
Re: Macro won't modify style in Word 2003
Quote:
I don't understand it...
me too, i get an empty document when i open your attachment, no code, no text
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.
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
1 Attachment(s)
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
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...
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 :)?
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...
Re: Macro won't modify style in Word 2003
Quote:
Originally Posted by
koolsid
Would you be interested in an alternative :)?
You missed my previous post :)
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,
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?
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