Thread: [Solved] Macro to highlight words
View Single Post
 
Old 07-01-2013, 12:36 PM
big0 big0 is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2013
Posts: 10
big0 is on a distinguished road
Default

Look through each of the vFindText in the code and add your word that you want highlighted. I see TWO vFindText CODES. One is Red and the other is blue, if you need additional colors. Then you can copy the start of code and the end of code and change to the next color. See below:

'highlight yellow words
Options.DefaultHighlightColorIndex = wdYellow
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

vFindText = Array("Teacher", "Students", "Grades")
vReplText = "^&"
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = False

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText
.Replacement.Highlight = True
.Execute replace:=wdReplaceAll
Next i
End With


Then copy and paste additional colors into the code below: Make sure you change

From this:
'highlight yellow words
Options.DefaultHighlightColorIndex = wdYellow

To this
'highlight green words
Options.DefaultHighlightColorIndex = wdGreen

and add
vFindText = Array("Next word", "Next word", "Next word")
Reply With Quote