Looking to delete all instances of a style in a word document. The basic function is easy enough to implement in VBA, by simply finding one instance of the style, using WordBasic to select similar formatting, and then deleting the selection:
Code: Select all
Sub SelectAllAnalytics()
'
' SelectAllAnalytics Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("analytic real")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
WordBasic.SelectSimilarFormatting
Selection.Delete
I need the last two lines of the code not to trigger if Selection.Find.Style finds nothing. I think this should be possible to do with COM objects but don't know how. Anyone have ideas?
The only other idea I had was to use keystrokes to go to the end of the document, hit return, and apply the style to an empty line to make sure the macro always finds something, but this is clunky and slow.
Thanks in advance.