Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
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 |
#2
Posted to microsoft.public.word.newusers
|
|||
|
|||
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 |
#3
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
"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? Hi Ed, Wildcards deal with patterns, and don't have any built-in concept of numbers. You probably need VBA. You could use a wildcard search first to find numbers between 60 and 89 ([6-8][0-9]), and then you'd need to check the number (last two characters in the selection) with VBA: Select Case Val(Right(Selection.Text,2)) Case 60 to 81 ' match End Select For wildcards to work in this case, you would need an "OR" operator, which does not exist in Word wildcards: [6][0-9] OR [7][0-9] OR [8][0-1] Regards, Klaus |
#4
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
I think the closet you can get would be finding 60-89.
App A, Item No. [6-8][0-9][!0-9] I assumed you wouldn't want to find part of: App A, Item No. 627 Try: Sub ScratchMacro() Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Text = "App A, Item No. [6-8][0-9][!0-9]" .MatchWildcards = True While .Execute If CLng(Mid(oRng, 17, 2)) 90 Then MsgBox oRng.Text End If Wend End With End Sub 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 |
#5
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
I think the closet you can get would be finding 60-89.
App A, Item No. [6-8][0-9][!0-9] I assumed you wouldn't want to find part of: App A, Item No. 627 Try: Sub ScratchMacro() Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Text = "App A, Item No. [6-8][0-9][!0-9]" .MatchWildcards = True While .Execute If CLng(Mid(oRng, 17, 2)) 90 Then MsgBox oRng.Text End If Wend End With End Sub 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 |
#6
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
Huge thanks to all of you Jay, Klaus, and Greg. I really appreciate the
assistance and the codes. Ed |
#7
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
Jay,
Are there advantages to Val(someString) over Clng(someString)? -- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. "Jay Freedman" wrote in message ... 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 |
#8
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
It's mostly that Val is stuck in my memory from about 30 years of use,
and CLng is much more recent. You know the short-term memory is the first to go. (My wife calls hers "momnesia".) In most cases, if you assign the result of Val to a Long variable, the result is identical to what you get from CLng, including the rounding of non-integers, and the results will compare as equal. There are some subtle differences, though. - If the string contains anything other than digits and a decimal point, Val will evaluate the start of the string up to (but not including) the non-numeric character. It will also strip out and ignore spaces, tabs, and line feeds. In the same situations, CLng will throw a type mismatch error, which needs to be trapped with On Error. This is not to say that Val is always superior. If you don't carefully validate the input, Val can give you a number that looks reasonable but is wrong, where CLng would clearly say "this is garbage". - Both functions will accept arguments in hexadecimal notation. But where CLng interprets all hex arguments as positive numbers, Val interprets 4-digit hex numbers larger than 7FFF as negative numbers (because the highest-order bit is considered to be a sign bit). You won't run into this one very often! -- 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. On Thu, 27 Jul 2006 17:24:29 -0400, "Greg Maxey" wrote: Jay, Are there advantages to Val(someString) over Clng(someString)? -- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. "Jay Freedman" wrote in message ... 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 |
#9
Posted to microsoft.public.word.newusers
|
|||
|
|||
Help with wildcard search, please?
Thanks Jay.
-- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. Jay Freedman wrote: It's mostly that Val is stuck in my memory from about 30 years of use, and CLng is much more recent. You know the short-term memory is the first to go. (My wife calls hers "momnesia".) In most cases, if you assign the result of Val to a Long variable, the result is identical to what you get from CLng, including the rounding of non-integers, and the results will compare as equal. There are some subtle differences, though. - If the string contains anything other than digits and a decimal point, Val will evaluate the start of the string up to (but not including) the non-numeric character. It will also strip out and ignore spaces, tabs, and line feeds. In the same situations, CLng will throw a type mismatch error, which needs to be trapped with On Error. This is not to say that Val is always superior. If you don't carefully validate the input, Val can give you a number that looks reasonable but is wrong, where CLng would clearly say "this is garbage". - Both functions will accept arguments in hexadecimal notation. But where CLng interprets all hex arguments as positive numbers, Val interprets 4-digit hex numbers larger than 7FFF as negative numbers (because the highest-order bit is considered to be a sign bit). You won't run into this one very often! Jay, Are there advantages to Val(someString) over Clng(someString)? -- Greg Maxey/Word MVP See: http://gregmaxey.mvps.org/word_tips.htm For some helpful tips using Word. "Jay Freedman" wrote in message ... 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 |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
In Word - how do you clear all the search fields | Microsoft Word Help | |||
File Search using the asterisk (*) wildcard | Microsoft Word Help | |||
File Search Preview Pane | Microsoft Word Help | |||
File Search Preview Pane | Microsoft Word Help | |||
Problem with search feature in word 2002 | Microsoft Word Help |