R
Raj
Hi,
I have a word document containing the following sentence.
All people in the city – big and small had arrived to watch the
marathon from start to finish
I am running the macro below (adapted from a post in this group) to
highlight the words in the vFindText array.
Sub HighlightWords()
Dim vFindText As Variant
Dim sReplText As String
Dim sHighlight As String
Dim i As Long
sHighlight = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
vFindText = Array("big", "small", "start", "finish")
sReplText = ""
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 = sReplText
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
Next i
End With
Options.DefaultHighlightColorIndex = sHighlight
End Sub
The problem: Only the words "big" and "finish" are getting highlighted
in green. The words "small" and "start" are not. What could be
problem?
Thanks in advance for the help.
Regards,
Raj
I have a word document containing the following sentence.
All people in the city – big and small had arrived to watch the
marathon from start to finish
I am running the macro below (adapted from a post in this group) to
highlight the words in the vFindText array.
Sub HighlightWords()
Dim vFindText As Variant
Dim sReplText As String
Dim sHighlight As String
Dim i As Long
sHighlight = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
vFindText = Array("big", "small", "start", "finish")
sReplText = ""
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 = sReplText
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
Next i
End With
Options.DefaultHighlightColorIndex = sHighlight
End Sub
The problem: Only the words "big" and "finish" are getting highlighted
in green. The words "small" and "start" are not. What could be
problem?
Thanks in advance for the help.
Regards,
Raj