Macros update - change only highlighted terms throughout document
Hello,
I have a find-replace Macro which I am using for replacing text in Word documents. However, there are certain words which I need to be replaced if they are highlighted in yellow and left as is if they are not.
For example (2 of the USD mentions below should have yellow highlight on them, but it doesn't work here):
XXXXXXXX USD
XXXXXXXXXX USD
XXXXXXXXXXXX USD
XXXXXXXX USD
XXXXXXXX USD
The Macro I have is the following, but the problem is that it is replacing USD everywhere in the document. Is there a way to update it so it changes only the yellow highlighted USD?
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = USD
.Replacement.Text = US Dollars
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Thanks for the help with this!
|