on not found

K

Kathy Webster

How do I tell a word macro to search for a character string, and do x, y and
z. But if the character string is NOT found, go to the end of the sub?
 
K

Kathy Webster

Found it on word.vba.beginners group...
If Selection.Find.Found = True Then
bla bla bla
End If
 
D

Doug Robbins - Word MVP

You can also use the Instr() function. It returns 0 if the string being
searched for is not found. Therefore

If Instr(string1, string2) = 0 Then ' string1 does not contain string2
Exit Sub
Else
'Do x, y and z
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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