Thread: Wildcard Search
View Single Post
 
Old 07-11-2020, 11:22 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default Wildcard Search

Puzzled by behavior of "<" in a wildcard search.


Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.Text = "An ax, a mule and an apple."
  With oRng.Find
    'This will find "only complete words" starting with a vowel.
    .Text = "<[AEIOUaeiou]*>"
    .MatchWildcards = True
    While .Execute
      oRng.Select
    Wend
  End With
  Set oRng = ActiveDocument.Range
  With oRng.Find
    'So why doens't this find "only complete words" ending with a vowel.
    .Text = "<*[AEIOUaeiou]>"
    .MatchWildcards = True
    While .Execute
      oRng.Select
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub


Here is a workaround but curious as to why the "<" seems to be ignored in second run above.



Code:
Sub KlunkyWordAround()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.Text = "An ax, a mule and an apple."
  Set oRng = ActiveDocument.Range
  With oRng.Find
    'This will find "only complete words" ending with a vowel.
    .Text = "[! ]@[AEIOUaeiou]>"
    .MatchWildcards = True
    .Wrap = wdFindStop
    Do While .Execute
      oRng.Select
      If oRng.End = 0 Then Exit Do
    Loop
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote