PDA

View Full Version : [SOLVED:] Something is wrong with my macro



ORANGESH
04-23-2014, 05:50 AM
Hi folks, I am recording macros in Word as an introduction to the language. I made this one this morning but it doesn't work for some reason. It's designed to insert a placeholder at the start of every paragraph of a certain style.


Sub insertplaceholder3()
'
' insertplaceholder3 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Customer Question Body Copy" _
)
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.TypeText Text:="<<response placeholder>>"
Selection.TypeParagraph
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("Body Copy")
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
End Sub


When I run the macro in Word, VBA pops up with an error message that says 'Expected: line number or label statement or end of statement.'

Is there an easy way to fix this?

Thanks
G

SamT
04-23-2014, 08:08 AM
:dunno
try changing
Selection.Find.Style = ActiveDocument.Styles("Customer Question Body Copy" _
) to
Selection.Find.Style = ActiveDocument.Styles("Customer Question Body Copy")
Should not make a difference, but :dunno

In any case, this post will bump you up the list, best I can do for you

Bob Phillips
04-23-2014, 11:39 AM
Maybe


Sub insertplaceholder3()
With Selection

.ClearFormatting
.Style = ActiveDocument.Styles("Customer Question Body Copy")
.MoveDown Unit:=wdParagraph, Count:=1
.TypeText Text:="<<response placeholder>>"
.TypeParagraph
.MoveUp Unit:=wdLine, Count:=1
.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
.Style = ActiveDocument.Styles("Body Copy")
.Range.HighlightColorIndex = wdYellow
End With
End Sub

ORANGESH
04-24-2014, 07:03 AM
Thanks for the suggestions folks, these didn't work, but I tried it again by saving the macro in the document rather than Normal.dotm, which removed the problem.
Cheers
George