Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I find all of the the "XX"

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US
how can I find all of the the "XX" in my document and have them all turn blue? this is what I am using:

With Selection.Find
.Text = "XX"
.MatchCase = True
End With
Do Until Selection.Find.Execute = False
Selection.Find.Execute
Selection.Font.Bold = wdToggle
Selection.Font.ColorIndex = wdBlue
Selection.Find.Execute
Loop

but it doesn't find all of them. Can anyone help?
Thanks in advance
eric "The greatest risk, is not taking one."
 
The problem is that Selection.Find is executing three times each loop. If I'm correct, you only need Selection.Find.Execute in the Do Until statement. Thus, as follows:

Do Until Selection.Find.Execute = False
Selection.Font.Bold = wdToggle
Selection.Font.ColorIndex = wdBlue
Loop

When you say Selection.Find.Execute with Do Until, it will actually do the command to return the boolean value. With the code that you pasted, it will skip the first one, color one, then proceed to skip two, color one. Thus, every third one will be changed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top