Stopping a loop within a Selection.Find

B

brotherescott

I am trying to write a macro that will go through the entire document
and highlight the text that is entered into a input box. I can get it
to work but I am having problems with the looping and how to stop it.
What can I trigger off of to say that the selection has reached the end
of the document and stop?

Here is what I have for code so far.
Thanks for any and all help.

Sub HighLightText()
Lookup = "scott" 'Word to highlight. It will be from a input box
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.StartIsActive = False
Do
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:=Lookup
Selection.Range.HighlightColorIndex = wdYellow
End With
Loop While Selection.Find.Found <> False
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top