View Single Post
 
Old 08-06-2020, 09:31 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You could use search to find numbers then expand to the word and use RegEx to see of the word has letters e.g. the following will find all the examples in this thread if they are in the main document text range



Code:
Sub Macro1()
Dim oRng As Range, oNum As Range
    Set oRng = ActiveDocument.Range
    With oRng.Find
        Do While .Execute(findText:="[0-9]{1,}", MatchWildcards:=True)
            Set oNum = oRng.Words(1)
            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
Dim objMatch As Object
Dim colMatches As Object

    Set objRegExp = CreateObject("VBScript.RegExp")
    objRegExp.Pattern = strFind
    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    If (objRegExp.Test(strText) = True) Then
        Set colMatches = objRegExp.Execute(strText)
        For Each objMatch In colMatches
            TestRegExp = True
            Exit For
        Next
    End If
    Set objRegExp = Nothing
    Set colMatches = Nothing
    Set objMatch = Nothing
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote