OR operator in Find and Replace

A

aussierugby

I need to find a way, ANY way to find either "shall" or "require" in a
document at the same time using the "Find and Replace" object/tool.
I'm using VBA to tag each location, but the order is of great
importance.

Heck, I'd buy beers at this point. :)
 
G

Greg Maxey

To the best of my knowledge it can't be done as you would expect.
Another user and I where discussing using OR in a find text problem. The
discussion turned to a very real human situation where the house is locked
and the car is locked. A known spare house key is in the car and a known
spare car hey is in the house. There are other keys somewhere to be found.
Obviously the problem is resolved and the search can end when either a house
or car key is found.


Sub HelmutsDilemma()
Dim aWord As Range
Dim myStr As String
For Each aWord In ActiveDocument.Range.Words
myStr = aWord
If InStrRev(myStr, " ") = Len(myStr) Then
myStr = Left(myStr, (Len(myStr) - 1))
End If
Select Case myStr
Case Is = "car", "house"
If aWord.Next(Unit:=wdWord, Count:=1) = "keys " Or _
aWord.Next(Unit:=wdWord, Count:=1) = "keys" Then
With aWord
.MoveEnd Unit:=wdWord, Count:=1
.Select
End With
Exit Sub
End If
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