Working with Templates
The Templates property on the Application object returns the Templates collection. The Templates collection provides you with access to the templates available in Word. Like most other collections in Word, you can use foreach to iterate over each Template in the Templates collection. You can also use the Templates collection's get_Item method to get to a particular template in the collection, passing by reference an object set to a string for the name of the template or an int for the 1-based index into the collection.You can also get to a Template object by using the Application object's NormalTemplate property, which returns a Template object for normal.dotthe global template that is always open and associated with a document when you have not specified a different template. If you have a Document object and you want to determine what template is associated with it, you can use the Document object's AttachedTemplate. When you get the value of AttachedTemplate, it returns an object that you can cast to a Template object. When you set the value of AttachedTemplate, you can pass either a Template object or a string containing the filename of the template.The Template object's OpenAsDocument method enables you to open a template as a document and edit it. The Name property is a string property that returns the name of the template, such as "Template.dot". FullName is a string property that returns the complete filename of the template, such as "c:\my templates\Template.dot". Path is a string property that returns the folder the template is in, such as "c:\my templates".
Types of Templates
The Template object's Type property returns a member of the WdTemplateType enumeration that designates the type of the template. A template can be one of three types. Figure 8-5 shows the Templates and Add-ins dialog which illustrates two of the three types. A template can be attached to a documentin this case the template AWTemplate.dot is attached to the active document. A template attached to a document has a type of wdAttachedTemplate. The Templates collection will contain an attached template only while the document the template is attached to is opened. When the document associated with the template is closed, the Template object attached to that document will no longer be in the Templates collection (unless of course it is attached to another document that is still open).
Figure 8-5. The Templates and Add-ins dialog showing the attached template and global templates.
