View Single Post
 
Old 08-05-2023, 01:45 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

Perhaps AI is not as good as you thought? If the idea is to optionally replace numbers with a string then the following will do that from the cursor position:
Code:
Sub Macro1()
Dim oRng As Range
Dim sAsk As String
Const sFindText As String = "[0-9]{1,}"
Const sReplaceText As String = "$1abc"
    Set oRng = Selection.Range
    oRng.End = ActiveDocument.Range.End
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        Do While .Execute(findText:=sFindText, _
                        MatchWildcards:=True, _
                        Forward:=True, _
                        Wrap:=wdFindStop) = True
            oRng.Select
            sAsk = MsgBox("Replace - " & vbCr & oRng.Text & vbCr + vbCr & _
                        "with - " & vbCr & sReplaceText, vbYesNo, _
                        "Replace Number")

            If sAsk = vbCancel Then GoTo lbl_Exit
                
            If sAsk = vbYes Then
                oRng.Text = sReplaceText
            End If
                oRng.Collapse wdCollapseEnd
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
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