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

Andrew,


Not fully flushed out, but this seems to capture the ones yours missed:

Code:
Sub FlagAlpaNumericWords()
Dim oRng As Range, oNum As Range
Dim bCompound As Boolean
Dim lngStart As Long
  Set oRng = ActiveDocument.Range
  With oRng.Find
    Do While .Execute(findText:="[0-9]{1,}", MatchWildcards:=True)
      bCompound = False
      Set oNum = oRng.Words(1)
      lngStart = oNum.Start
      Do While oRng.Characters.First.Previous = "-"
        oRng.MoveStart wdCharacter, -1
        oRng.MoveStart wdWord, -1
        oNum.Start = oRng.Start
        bCompound = True
      Loop
      Do While oRng.Characters.Last.Next = "-"
        oRng.MoveEnd wdCharacter, 1
        oRng.MoveEnd wdWord, 1
        bCompound = True
      Loop
      If bCompound Then
        Set oNum = oRng
        If oNum.Start > lngStart Then oNum.Start = lngStart
        oNum.Select
      Else
        oNum.End = oNum.End - 1
      End If
      If TestRegExp("[A-Z]", oNum.Text) = True Then
        oNum.HighlightColorIndex = wdYellow
      End If
      oRng.Collapse 0
    Loop
  End With
End Sub

Function TestRegExp(strFind As String, strText As String) As Boolean
Dim objRegExp As Object
  Set objRegExp = CreateObject("VBScript.RegExp")
  objRegExp.Pattern = strFind
  objRegExp.IgnoreCase = True
  objRegExp.Global = True
  TestRegExp = objRegExp.Test(strText)
  Set objRegExp = Nothing
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 08-11-2020 at 04:07 PM.
Reply With Quote