I am trying to write a macro which uses the Word objects to create a Word document based on a Word template document.
I am having some difficulties when I use Option Explicit. Without it I can just omit the Dim ... line but I would like that there.
Here is the code so far:
Option Explicit
Sub PopulateWordDoc()
Dim wApp As Object
Set wApp = CreateObject("Word.Application")
Dim wdDoc As Word.Document ' User-defined type not defined error on this line
Set wDoc = wApp.Documents.Open("C:\path\WordTestTemplateDoc.dotx", ReadOnly:=False)
With wDoc
.Content.Find.Execute FindText:="<Project ID>", ReplaceWith:="This is the project id....."
.SaveAs2 Filename:=("C:\path\NewWordDoc.docx"), FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
End With
End Sub