View Single Post
 
Old 01-27-2023, 10:17 PM
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

The code I posted runs the searches separately. To do what you suggest requires two macros similar to
Code:
Sub Macro1()
Dim sFindText As String
Dim sReplaceText As String
Dim oRng As Range
    sFindText = "%"
    sReplaceText = " PERCENT"
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        Do While .Execute(findText:=sFindText, _
                          MatchWholeWord:=True, _
                          Forward:=True, _
                          Wrap:=wdFindStop) = True
            oRng.Text = sReplaceText
            oRng.Collapse wdCollapseEnd
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Exit Sub
End Sub


Sub Macro2()
Dim sFindText As String
Dim sReplaceText As String
Dim oRng As Range
    sFindText = "\"
    sReplaceText = " "
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        Do While .Execute(findText:=sFindText, _
                          MatchWholeWord:=True, _
                          Forward:=True, _
                          Wrap:=wdFindStop) = True
            oRng.Text = sReplaceText
            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