Find, then loop with Find Next?

E

Ed

I've got a Selection.Find inside a loop. If Find.Found = True, I've got
five other IFs that the selection must meet before I can take action.
Somewhere in this mess, I've got to say Found = True, but it fails the other
conditions, so go find the next one and check it until Found = False. I'm
having trouble wrapping my brain around this one - any help or examples are
appreciated.

Ed
 
P

Peter Hewett

Hi Ed

have a look at this, the code aint complete as I've not bother to declare the
variable in the IF statement, but you'll get the idea - I hope!

Public Sub TestFind()
' Setup for the search
With Selection.Find
.ClearFormatting
.Text = "FindMe"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

' Find the required text
Do While Selection.Find.Execute

' You're only here if we found something
If a = True And b = True And c = True And d = True Then

' Now you do something
End If
Loop
End Sub

HTH + Cheers - Peter
 
E

Ed

Thank you, Peter. I'll give it a shot.
Ed

Peter Hewett said:
Hi Ed

have a look at this, the code aint complete as I've not bother to declare the
variable in the IF statement, but you'll get the idea - I hope!

Public Sub TestFind()
' Setup for the search
With Selection.Find
.ClearFormatting
.Text = "FindMe"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With

' Find the required text
Do While Selection.Find.Execute

' You're only here if we found something
If a = True And b = True And c = True And d = True Then

' Now you do something
End If
Loop
End Sub

HTH + Cheers - Peter
 

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