Find Method

D

David Yeager

I have a somewhat difficult to explain problem:

I'm trying to find all instances of a certain string
through VBA, but the Find method doesn't seem to work
quite the same way in VBA as it does in Word itself.

Basically, I'm looking for instances of an old tag used in
old text files. Let me post the code:

With Selection.Find
.ClearFormatting
.MatchWildcards = True
.Text = "\{headbi\}*[{<]"
Do While intHeadBiLoopCounter <> 0
.Execute
strHeadBiArray(intHeadBiLoopCounter) =
Selection.Text
Debug.Print strHeadBiArray
(intHeadBiLoopCounter)
intHeadBiLoopCounter = intHeadBiLoopCounter - 1
Debug.Print intHeadBiLoopCounter
Loop
End With

The problem here is that the code only hits EVERY OTHER
instance of {headbi}*[{<]... for some reason it skips over
the next {headbi} after finding one. Anybody have any
idea what I'm doing wrong?

-Dave
 
D

Doug Robbins - Word MVP

Hi David,

What is the initial value of intHeadBiLoopCounter?

Try using the following construction:

intHeadBiLoopCounter = ?????
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText: = "\{headbi\}*[{<]", MatchWildcards: =
True, Wrap:=wdFindContinue, Forward:=True) = True
strHeadBiArray(intHeadBiLoopCounter) = Selection.Range.Text
intHeadBiLoopCounter = intHeadBiLoopCounter - 1
Loop
End With

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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