FIGURE 6.7
Selecting a folder as the Contact Documents folder.
The NewDocFromTemplatefunction listed next creates a new document based on a template in
the Contact Templates folder, using Word document properties to hold the data from Access. The
document properties method is the most common technique I use for creating documents to fill
with Access data. In the NewDocFromTemplateprocedure, after creating the new document, the
names of its document properties are printed to the Immediate window.
As with previous versions of Word, although there is a CustomProperties collection in
the Word 2007 object model, and a CustomPropertyobject, this collection and
object actually belong to the Smart Tags, so if you declare variables of these data types, you will get a
compile error; therefore, they must be declared as Object.
Public Function NewDocFromTemplate()
On Error GoTo ErrorHandler
Dim appWord As Word.Application
Dim docs As Word.Documents
Dim strLetter As String
Dim strTemplateDir As String
Dim doc As Word.Document
NOTENOTE
Part II Writing VBA Code to Exchange Data between Office Components