Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-05-2023, 01:45 AM
gmayor's Avatar
gmayor gmayor is offline After first replacement, other search results are incorrectly selected Windows 10 After first replacement, other search results are incorrectly selected Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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
 

Tags
prompt, regex, replacing



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to keep a list of search results Jedothek Word 2 08-19-2020 07:22 AM
2013 search results take a long time - they fill in as results in reverse date order themookman Outlook 0 10-11-2013 12:01 PM
After first replacement, other search results are incorrectly selected Outlook search too many results alexb123 Outlook 1 10-10-2013 09:53 AM
Search results disappearing Emerogork Office 3 07-17-2011 03:52 PM
Instant Search's "Display search results as I type when possible" with Exchange lwc Outlook 0 06-01-2011 01:56 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft