The Template Object
The Template object represents a Word template. Template objects are kept in the Templates collection, which includes all available Word templates at a given moment, that is:
All templates that are open as documents
All templates that are attached to open documents
All global templates that appear in the Templates and Add-ins dialog box (under the Tools menu)
The Normal template
The Templates collection does not include all .dot files on the hard disk.
The AttachedTemplate Property
Note that the Document object has an AttachedTemplate property that returns the Template object that is attached to the document. Thus, the code:
MsgBox ActiveDocument.AttachedTemplate.Name
will display the name of the template attached to the currently active Word document.
Properties and Methods of the Template Object
The Template object has only two methods: Save and OpenAsDocument. The latter method is actually quite important, because some of the properties of a template can be accessed only when the template is opened as a document. For example, to access the formatting styles in a template, it must be opened as a document.
To be perfectly clear, the OpenAsDocument method will open, as a document, a template that is in the Templates collection, which means the template is already “open” in some sense. To open a template that is on the disk as a document, we must use the Open method of the Documents collection. (I discuss this method in Chapter 12, The Document Object.)
To illustrate the ...
Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.