View Single Post
 
Old 02-14-2019, 09:09 AM
koehlerc14 koehlerc14 is offline Windows 10 Office 2016
Novice
 
Join Date: Feb 2019
Posts: 6
koehlerc14 is on a distinguished road
Default Function in a Macro used to Find & Replace

I have a Macro that I'm trying to make more efficient and also be able to share & update a little easier. My attempt was to create a function that could be called for upwards of 25 corrections that change over time and should be easy to update with just one line of code calling the function.

Can anyone deduce what I am trying to do and what I'm writing incorrectly?

Code:
Private Function Simple_FindReplace(docFind As Document, strFind As String, _
                                    strReplace As String)
 
        With docFind.Range.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = strFind
            .Replacement.Text = strReplace
            .Execute Replace:=wdReplaceAll
        End With
End Function
Sub DocOps_SPD_Rewrites()
    With Document.Range.Find
 
    'SPD Changes - Updated 2.14.2019
 
          Call Simple_FindReplace("BEFORE text", "AFTER text")
          Call Simple_FindReplace("BEFORE test", "AFTER test")
          Call Simple_FindReplace("BEFORE tent", "AFTER tent")
    End With
End Sub
Reply With Quote