CPGDeveloper
Board Regular
- Joined
- Oct 8, 2008
- Messages
- 172
I have VBA code that's repeatedly going through a document changing one style to another...something like this:
'Remove StyleA
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("StyleA")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("StyleA1")
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
I have about a dozen of these changes to make in this macro and simply repeat the above code, just replacing the style names that I want changed. Currently, the code takes something like 20 seconds to run. Does anyone know of a way to combine all of them into a simpler and/or more efficient statement? Any tips would be greatly appreciated. Thanks.
'Remove StyleA
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("StyleA")
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("StyleA1")
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
I have about a dozen of these changes to make in this macro and simply repeat the above code, just replacing the style names that I want changed. Currently, the code takes something like 20 seconds to run. Does anyone know of a way to combine all of them into a simpler and/or more efficient statement? Any tips would be greatly appreciated. Thanks.