Logical OR in Word wildcard searches

W

wildetudor

Hey everyone,

I'm in a situation where I need to search for text in my document with words
that have several possible alternatives - and for that I need to use a
logical OR between them. If I'd used a Google search syntax for example, it
would have been easy - e.g. "having a headache OR migraine", but in Word I
don't know how to do it, and could not find anything about this in the Word
Help.

Can anyone advise me how to do this? Anticipated thanks!
 
T

Tony Jollans

Sorry, you can't do that with a single Find operation in Word. You will need
to do multiple Finds but you can automate the operation to a certain extent
with VBA if you want.
 
G

Greg Maxey

As previously posted there isn't really a method of using OR in Word Find
and Replace routines. You can use a bit of VBA brute force to the same
effect:

Sub HelmutsDilemma()
Dim aWord As Range
Dim pLast As String
For Each aWord In ActiveDocument.Range.Words
If aWord.Characters.Last = " " Then
pLast = " "
Else
pLast = ""
End If
Select Case Trim(aWord.Text)
Case Is = "headache", "migraine"
aWord = "sore head" & pLast
Case Else
'Do Nothing
End Select
Next
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