View Single Post
 
Old 05-18-2022, 11:23 PM
JasonLZH JasonLZH is offline Windows 10 Office 2019
Novice
 
Join Date: May 2022
Posts: 1
JasonLZH is on a distinguished road
Default VBA to Replace Text in Multiple Text Boxes

Hi, guys. I'm new to Word VBA and I would like to ask some questions here.

Let's say my word file has a few words named "[Name1]" and these words are located in multiple text boxes in a word file. Then, I want to change [Name1] to a person's name, and that's all.

I can replace these words if I do it manually, but it failed when I tried to use the following VBA codes:

Code:
Sub Macro2_Backup()

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "[Name1]"
        .Replacement.Text = "Mike"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
End Sub
I tried to find some ideas online but none of them clearly solved my doubts. Therefore, I would like to ask if there is someone who can show me a simple VBA code to replace words across multiple text boxes in a Word File.
Reply With Quote