Hi,

I have a word document containing the following sentence.

All people in the city =96 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 =3D Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex =3D wdBrightGreen
vFindText =3D Array("big", "small", "start", "finish")
sReplText =3D ""
With Selection.Find
.Forward =3D True
.Wrap =3D wdFindContinue
.MatchWholeWord =3D True
.MatchWildcards =3D False
.MatchSoundsLike =3D False
.MatchAllWordForms =3D False
.Format =3D True
.MatchCase =3D False
For i =3D LBound(vFindText) To UBound(vFindText)
.Text =3D vFindText(i)
.Replacement.Text =3D sReplText
.Replacement.Highlight =3D True
.Execute Replace:=3DwdReplaceAll
Next i
End With
Options.DefaultHighlightColorIndex =3D 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

Re: Problem with highlighting words by Raj

Raj
Mon Jul 14 05:10:39 PDT 2008

On Jul 14, 4:41=A0pm, Raj <rsp...@gmail.com> wrote:
> Hi,
>
> I have a word document containing the following sentence.
>
> All people in the city =96 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 =3D Options.DefaultHighlightColorIndex
> Options.DefaultHighlightColorIndex =3D wdBrightGreen
> vFindText =3D Array("big", "small", "start", "finish")
> sReplText =3D ""
> With Selection.Find
> =A0 =A0.Forward =3D True
> =A0 =A0.Wrap =3D wdFindContinue
> =A0 =A0.MatchWholeWord =3D True
> =A0 =A0.MatchWildcards =3D False
> =A0 =A0.MatchSoundsLike =3D False
> =A0 =A0.MatchAllWordForms =3D False
> =A0 =A0.Format =3D True
> =A0 =A0.MatchCase =3D False
> =A0 =A0For i =3D LBound(vFindText) To UBound(vFindText)
> =A0 =A0 =A0 =A0.Text =3D vFindText(i)
> =A0 =A0 =A0 =A0.Replacement.Text =3D sReplText
> =A0 =A0 =A0 =A0.Replacement.Highlight =3D True
> =A0 =A0 =A0 =A0.Execute Replace:=3DwdReplaceAll
> =A0 =A0Next i
> End With
> Options.DefaultHighlightColorIndex =3D 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 something more to say about the problem:
I cleaned up the highlighting and ran the macro again. It now
highlights only the "big" . None of the other three words in the
sentence are highlighted.

Thanks and Regards,
Raj

RE: Problem with highlighting words by JeanGuyMarcil

JeanGuyMarcil
Mon Jul 14 05:35:01 PDT 2008

"Raj" wrote:

> 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.

Try this instead:

Dim vFindText As Variant
Dim sReplText As String
Dim sHighlight As String
Dim i As Long
Dim rngStart As Range
Dim rngFind As Range

Set rngStart = Selection.Range
Set rngFind = ActiveDocument.Range

sHighlight = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdBrightGreen
vFindText = Array("big", "small", "start", "finish")
sReplText = ""

With rngFind.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
Set rngFind = ActiveDocument.Range
Next i
End With

Options.DefaultHighlightColorIndex = sHighlight

rngStart.Select

RE: Problem with highlighting words by stevencraigmiller(at)comcast(dot)net>

stevencraigmiller(at)comcast(dot)net>
Mon Jul 14 05:36:02 PDT 2008

To: Raj,

I don't know why, and perhaps there is yet a better solution, but you might
try:

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 = ""
For i = LBound(vFindText) To UBound(vFindText)
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = False
.Text = vFindText(i)
.Replacement.Text = sReplText
.Replacement.Highlight = True
.Execute Replace:=wdReplaceAll
End With
Next i
Options.DefaultHighlightColorIndex = sHighlight
End Sub

Steven Craig Miller

"Raj" wrote:

> 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
>

Re: Problem with highlighting words by Raj

Raj
Mon Jul 14 06:15:25 PDT 2008

On Jul 14, 5:36=A0pm, StevenM <stevencraigmiller(at)comcast(dot)net>
wrote:
> To: Raj,
>
> I don't know why, and perhaps there is yet a better solution, but you mig=
ht
> try:
>
> Sub HighlightWords()
> =A0 =A0 Dim vFindText As Variant
> =A0 =A0 Dim sReplText As String
> =A0 =A0 Dim sHighlight As String
> =A0 =A0 Dim i As Long
> =A0 =A0 sHighlight =3D Options.DefaultHighlightColorIndex
> =A0 =A0 Options.DefaultHighlightColorIndex =3D wdBrightGreen
> =A0 =A0 vFindText =3D Array("big", "small", "start", "finish")
> =A0 =A0 sReplText =3D ""
> =A0 =A0 For i =3D LBound(vFindText) To UBound(vFindText)
> =A0 =A0 =A0 =A0 With Selection.Find
> =A0 =A0 =A0 =A0 =A0 =A0 .Forward =3D True
> =A0 =A0 =A0 =A0 =A0 =A0 .Wrap =3D wdFindContinue
> =A0 =A0 =A0 =A0 =A0 =A0 .MatchWholeWord =3D True
> =A0 =A0 =A0 =A0 =A0 =A0 .MatchWildcards =3D False
> =A0 =A0 =A0 =A0 =A0 =A0 .MatchSoundsLike =3D False
> =A0 =A0 =A0 =A0 =A0 =A0 .MatchAllWordForms =3D False
> =A0 =A0 =A0 =A0 =A0 =A0 .Format =3D True
> =A0 =A0 =A0 =A0 =A0 =A0 .MatchCase =3D False
> =A0 =A0 =A0 =A0 =A0 =A0 .Text =3D vFindText(i)
> =A0 =A0 =A0 =A0 =A0 =A0 .Replacement.Text =3D sReplText
> =A0 =A0 =A0 =A0 =A0 =A0 .Replacement.Highlight =3D True
> =A0 =A0 =A0 =A0 =A0 =A0 .Execute Replace:=3DwdReplaceAll
> =A0 =A0 =A0 =A0 End With
> =A0 =A0 Next i
> =A0 =A0 Options.DefaultHighlightColorIndex =3D sHighlight
> End Sub
>
> Steven Craig Miller
>
>
>
> "Raj" wrote:
> > Hi,
>
> > I have a word document containing the following sentence.
>
> > All people in the city =96 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 =3D Options.DefaultHighlightColorIndex
> > Options.DefaultHighlightColorIndex =3D wdBrightGreen
> > vFindText =3D Array("big", "small", "start", "finish")
> > sReplText =3D ""
> > With Selection.Find
> > =A0 =A0.Forward =3D True
> > =A0 =A0.Wrap =3D wdFindContinue
> > =A0 =A0.MatchWholeWord =3D True
> > =A0 =A0.MatchWildcards =3D False
> > =A0 =A0.MatchSoundsLike =3D False
> > =A0 =A0.MatchAllWordForms =3D False
> > =A0 =A0.Format =3D True
> > =A0 =A0.MatchCase =3D False
> > =A0 =A0For i =3D LBound(vFindText) To UBound(vFindText)
> > =A0 =A0 =A0 =A0.Text =3D vFindText(i)
> > =A0 =A0 =A0 =A0.Replacement.Text =3D sReplText
> > =A0 =A0 =A0 =A0.Replacement.Highlight =3D True
> > =A0 =A0 =A0 =A0.Execute Replace:=3DwdReplaceAll
> > =A0 =A0Next i
> > End With
> > Options.DefaultHighlightColorIndex =3D 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- Hide quoted text -
>
> - Show quoted text -

Hi Jean-Guy and Steven,

Thanks a lot. Both solutions worked.

Regards,
Raj

Re: Problem with highlighting words by stevencraigmiller(at)comcast(dot)net>

stevencraigmiller(at)comcast(dot)net>
Mon Jul 14 07:06:01 PDT 2008

To: Raj,

While it doesn't seem to make a whole lot of difference, you might consider
changing: Dim sHighlight As String
To: dim nHighlight as Long

And then change the 's' to 'n' for the Highlight variable.

If you do a search in help for DefaultHighlightColorIndex, you'll see that
it returns a long variable. But it seems to work either way.

Steven Craig Miller

"Raj" wrote:

> On Jul 14, 5:36 pm, StevenM <stevencraigmiller(at)comcast(dot)net>
> wrote:
> > To: Raj,
> >
> > I don't know why, and perhaps there is yet a better solution, but you might
> > try:
> >
> > 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 = ""
> > For i = LBound(vFindText) To UBound(vFindText)
> > With Selection.Find
> > .Forward = True
> > .Wrap = wdFindContinue
> > .MatchWholeWord = True
> > .MatchWildcards = False
> > .MatchSoundsLike = False
> > .MatchAllWordForms = False
> > .Format = True
> > .MatchCase = False
> > .Text = vFindText(i)
> > .Replacement.Text = sReplText
> > .Replacement.Highlight = True
> > .Execute Replace:=wdReplaceAll
> > End With
> > Next i
> > Options.DefaultHighlightColorIndex = sHighlight
> > End Sub
> >
> > Steven Craig Miller
> >
> >
> >
> > "Raj" wrote:
> > > 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- Hide quoted text -
> >
> > - Show quoted text -
>
> Hi Jean-Guy and Steven,
>
> Thanks a lot. Both solutions worked.
>
> Regards,
> Raj
>