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
>