View Single Post
  #2   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Help with wildcard search, please?

Hi Ed,

Yes, you're going to need VBA. The Find mechanism itself can't do
comparisons of the values of digits. You need something like this:

Dim myRange As Range
Dim myVal As Long

Set myRange = ActiveDocument.Range
FoundIt = False

With myRange.Find
.MatchWildcards = True
.Text = "App A, Item No. ([0-9]{2})"
.Forward = True
.Wrap = wdFindStop
Do While .Execute
myVal = Val(Right$(myRange.Text, 2))
If (60 = myVal) And (myVal = 81) Then
myRange.Select ' or do something else
Exit Do
End If
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain
string ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than
this but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed