T
Tarallen
Hi,
I am writing a macro to replace several styles in a document with new
styles. I used the Macro recorder with the Find-Replace feature in Word but
the macro is not working. I get the Run time error. I am still learning how
to manipulate recorded macros using VBA. I have included a short one below -
it is replacing Heading 1 style with Heading 2: Topic style. Can someone take
a look at it and let me know if anything jumps out at you as incorrect.
Sub TestUpdate()
'
' TestUpdate Macro
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("H1:Lesson")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
I am writing a macro to replace several styles in a document with new
styles. I used the Macro recorder with the Find-Replace feature in Word but
the macro is not working. I get the Run time error. I am still learning how
to manipulate recorded macros using VBA. I have included a short one below -
it is replacing Heading 1 style with Heading 2: Topic style. Can someone take
a look at it and let me know if anything jumps out at you as incorrect.
Sub TestUpdate()
'
' TestUpdate Macro
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 2")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("H1:Lesson")
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub