Microsoft Office 2000/Visual Basic Programmer's Guide   

Word Templates

Word is ideal for creating custom word-processing solutions. You can take advantage of Word's power to easily create nicely formatted invoicing, reporting, and form letter applications, to name just a few.

Every Word document has an associated VBA project. However, code that you write in one document isn't easily available to other documents. If you're creating a solution in Word, it makes sense to create a custom document template and distribute that template to your users. That way, a number of different documents can call the code in the template. The same holds true for custom styles, toolbars, and recorded macros.

To further illustrate the advantages of packaging code in a template, consider the New event for a Word Document object. This event occurs when you create a new document from a template. The Document_New event procedure itself must reside in the template project; there's no reason to use it in a regular Word document (.doc file), since you can't create a new document from another document.

For more information about when to create a template and when to create an add-in, see "Word Document Templates vs. Word Add-ins (Global Templates)" later in this chapter.

The following sections briefly discuss the different templates you can use to distribute a Word solution.