I?m a newbie to VBA, so apologies in advance.
With a macro in MS Word, I want to find and highlight all instances of a given text string, plus loop in order to do this for all text strings in an array/collection, {txt_string1,txt_string2,txt_string3,…}. The array/collection will have 65-80 text strings.
As a starting point, I have recorded a macro that ran once successfully for the text string ?cannot?, but then it would not run again; don?t know why. Here?s the code for that macro.
Sub highlight_txt_string_cannot()
‘
‘ highlight_txt_string_cannot Macro
‘ Macro recorded 9/14/2007 by Thomas S. Auchterlonie
‘
Selection.Find.ClearFormatting
With Selection.Find
.Text = “cannot”
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Range.HighlightColorIndex = wdYellow
End Sub
I think that I need to loop through the array/collection using a For Each ? Next construct, but I don?t know how to set that up. Nor do I know how to set up the array/collection.
Thanks in advance.