View Single Post
 
Old 01-03-2025, 06:24 AM
robnun robnun is offline Windows 11 Office 2021
Novice
 
Join Date: Dec 2020
Location: TX, USA
Posts: 8
robnun is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Hi! Try this code:
Code:
Sub FindReplaceAll()

Dim RngTxt as range, StrFind As String, StrRepl As String
Dim i As Long
    StrFind = "<,>,#"
    StrRepl = "-,-,-"

    Selection.Collapse Direction:=wdCollapseStart
    Set RngTxt = Selection.range
    Selection.PasteSpecial DataType:=wdPasteText
    RngTxt.End = Selection.range.End
    RngTxt.Select

    For i = 0 To UBound(Split(StrFind, ","))
        Selection.Find.ClearFormatting
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .text = Split(StrFind, ",")(i)
            .Replacement.text = Split(StrRepl, ",")(i)
            .Format = False
            .MatchWholeWord = True
            .MatchAllWordForms = False
            .MatchWildcards = False
            .Execute Replace:=wdReplaceAll
        End With
    Next i
    Selection.Copy
End Sub
Thank you, Vivka. Your solution worked perfectly!
Reply With Quote