Hi All-
I'm trying to use a VBA in access to open up an existing Word template, then find/replace several bits of text through the document (with data in a field on my form) before re-saving as a pdf with a new naming convention. So far, I've been able to get the Word Document to open and then re-save properly, but I can't get the find/replace functionality to work. Could someone please take a look at my VBA and let me know where I've gone wrong? Here's what I'm using:
Code:
Private Sub btnEmailSupplier_Click()
'opens template
Dim db As DAO.Database
Dim objWord As Word.Application
Set objWord = New Word.Application
With objWord
.Documents.Open "mypath to word.docx"
.Visible = True
.Activate
End With
'Replaces date on first page
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "replace first date "
.Replacement.Text = Me.CP_Return_By
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Thank you!