[RESOLVED] Finding occurences of a word in Microsoft Word
I use the following to find a word in a word document opened in a DSOFramer ActiveX control:
Code:
oDoc = ctl.ActiveDocument
oDoc.ActiveWindow.Selection.WholeStory()
oDoc.ActiveWindow.Selection.Find.ClearFormatting()
oDoc.ActiveWindow.Selection.Find.Replacement.ClearFormatting()
With oDoc.ActiveWindow.Selection.Find
.Text = "control"
.Forward = True
.Wrap = WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
oDoc.ActiveWindow.Selection.Find.Execute()
The code finds and highlights the first occurence of the word "control" but ignores all of the other occurences.
What am I doing wrong ? I must be missing something easy.
Re: Finding occurences of a word in Microsoft Word
Leave your current code in place, but instead of doing the Selection.Find.Execute(), do a
Code:
Selection.Find.HitHighlight "control"
Re: Finding occurences of a word in Microsoft Word
If you Record a Macro it will usually show you the code office apps use to complete the desired task.
Re: Finding occurences of a word in Microsoft Word
Quote:
Originally Posted by RobDog888
If you Record a Macro it will usually show you the code office apps use to complete the desired task.
That's the way I usually do it, but I had to figure out the HitHighlight because the recording didn't happen to catch that.