Using Access VBA to Find/Replace text in a Word doc

Access 2013
Excel 2010

I'm trying to find/replace text in a word doc from access vba.  The following code works except when "[A]" is inside a textbox in the word file.  What am I missing?

Const wdReplaceAll = 2
 Set objapp = CreateObject("Word.Application")

            objapp.Visible = True
            objapp.Activate  'Bring to front
            Set w = objapp.Documents.Open("Template.docx", ReadOnly:=True)
            Set s = objapp.Selection
            s.Find.Text = "[A]"
            s.Find.Replacement.Text = "123"
            s.Find.Execute , , , , , , , , , , wdReplaceAll
Who is Participating?
Rgonzo1971Connect With a Mentor Commented:

pls try

For Each txtbox In ActiveDocument.Shapes
    If txtbox.Type = msoTextBox Then
        If txtbox.TextFrame.TextRange.Text Like "*[A]*" Then
            txtbox.TextFrame.TextRange.Text = Replace(txtbox.TextFrame.TextRange.Text, "[A]", "123")
        End If
    End If

Open in new window

pderingAuthor Commented:
worked great!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.