O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required