View Single Post
 
Old 01-02-2025, 01:22 PM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

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, ","))
        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

Last edited by vivka; 01-03-2025 at 10:26 AM.
Reply With Quote