Thread: Wildcard Search
View Single Post
 
Old 07-12-2020, 05:13 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

It looks like the Covid-19 lockdown is getting to you Greg. I thought it was a strange coincidence when the other thread appeared after yours.

Ignoring the compound words complication, the code could be as below. I think you could even add a \- into the search strings to include the compound words.
Code:
Sub ScratchMacro2()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  oRng.HighlightColorIndex = wdAuto
  oRng.Text = "Mary has an ax, a mule and an apple." & vbCr & "Tom conducted a low-grade in-depth on-site inspection."
  With oRng.Find
    .Text = "<[AEIOUaeiou]*>"   'starts with a vowel
    .MatchWildcards = True
    .Wrap = wdFindStop
    Do While .Execute
      Select Case lcase(Right(Trim(oRng), 1))
        Case "a", "e", "i", "o", "u" 'also ends with a vowel
          oRng.HighlightColorIndex = wdBlue
        Case Else     'starts but doesn't end with a vowel
          oRng.HighlightColorIndex = wdYellow
      End Select
      oRng.Collapse wdCollapseEnd
    Loop
  End With
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "<[A-z]@[AEIOUaeiou]>"    'Find words starting with a vowel
    .MatchWildcards = True
    .Highlight = False            'and not already highlighted
    While .Execute
      oRng.Select
      oRng.HighlightColorIndex = wdBrightGreen
      oRng.Collapse wdCollapseEnd
    Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote