Home

MacOffice

Using Global Templates to add functionality to MacWord

Global templates, also called add-ins, are, as the name implies, templates that apply to all documents, as opposed to document templates which apply only to documents to which they are attached. Global templates can contain autotext entries, macros, and custom toolbars and keyboard shortcuts, thus giving Word new functionality that works for any document. The Normal template is a special case in that it is always a global template and it is the default document template.

A global template can also contain automacros, which run when the template is opened or closed, allowing you to configure Word's preferences, for example, to make sure that your environment is exactly the way you like it every time.

The Normal template

By default, macros, autotext and customizations are stored in the Normal template. Since the Normal template is used as a scratch pad for the application as well as any documents that use it as their document template, it tends to be much more susceptible to corruption. If the Normal template corrupts, the standard fix is to rename it (with Word closed), restart Word, which creates a new Normal template, then use the Organizer to transfer items from the old version. Of course if the template is corrupted, there's no guarantee that the items will be available. For more on the Normal template, click here (link to new Normal template article).

Global templates tend to be far less susceptible to corruption. I've used global templates for years without any problems. Global templates have another advantage, in that they can be used to split up the functionalities, either for easier troubleshooting during development, or for flexibility in configuring Word. For instance, everyone on a network could share a global template with some basic macros, autotext, etc., and individual users can have their own customizations in a local global template.

Creating global templates

Global templates, like any other template can be created by saving the file with the Format set to Document Template and saving it in the Startup Folder or another add-in location (see below). You can also simply copy the Normal template to the Startup folder and rename it (Word can't use more than one Normal at a time).

Loading global templates

Global templates which are stored in either of two folders are automatically loaded when Word is started. The first is the Microsoft Office <your version>:Office:Startup:Word folder; the second is the folder designated using Preferences/File Locations/Startup.

Global templates can also be loaded manually using the Tools/Templates and Add-ins dialog:

Macros

Regular macros

Macros in global templates can be called at any time, regardless of which document template is active. When calling a macro using Tools/Macro/Macros... dialog, be sure the Macros in dialog is set to All active documents and templates, or to the specific global template that the macro resides in.

Automacros

Automacros and Event macros execute when certain events take place -- a document is opened, closed, changed, etc. Unlike MacXL, where automacros have been almost entirely replaced in current programming by event macros, MacWord's event macros (Document_Open(), Document_Close(), Document_New()) - either by design or a bug, don't fire when global templates are loaded. However, the older automacro AutoExec() will fire. This can then be used to perform an action on startup, such as configuring toolbars, setting preferences, etc.

Toolbars

Attaching custom toolbars

Toolbars are stored in templates or documents, by default the Normal template. But they can be attached to global templates just as they can with any other document, using the Tools/Customize menu command. With the global template open, create a new toolbar using the New button, and set the Save in: dropdown to that template

.

Using a macro to set up toolbars

Using a macro to create toolbars has a couple of advantages. One is that you can set properties that aren't available via the GUI (such as protection, the row index, parameters, making the toolbar temporary, etc). Another is that the toolbar will be created just the way you want it every time, even if you, someone else, or a macro modify the toolbar during a session.

You can see an example of how to implement a toolbar in code at my page on creating a replacement standard toolbar.

Keyboard shortcuts

The Customize Keyboard dialog

Like the Customize Toolbars dialog, the Word Customize Keyboard dialog allows you to choose which template the shortcut is stored in. If you store the shortcut in a global template, the shortcut will be available to each document, regardless of which document template is in use.

Setting keyboard shortcuts using VBA

Of course, if you want to make sure that the user doesn't change the keyboard shortcut, you can create the keyboard shortcut in code in a global template. For example to assign CMD-OPT-W to the FileClose command:

    CustomizationContext = ThisDocument.AttachedTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyW, wdKeyCommand, wdKeyOption), _
        KeyCategory:=wdKeyCategoryCommand, Command:="FileClose"

and to restore it when closing the add-in:

    CustomizationContext = ThisDocument.AttachedTemplate
    FindKey(BuildKeyCode(wdKeyW, wdKeyCommand, wdKeyOption)).Disable

Setting preferences

Setting preferences via code in a global template allows you to configure your environment precisely each time you open Word. If I suspect my Word Settings file has gotten corrupted, I never worry about trashing it - I set all my prefs in my startup global template. You can see a modified version of my Set_Preferences() macro. I call it from the Auto_Exec() macro of my startup global template.

Using the Organizer to transfer macros, autotext, etc.

You can use the Organizer to transfer macros, autotext, and toolbars from any template to your global template. Choose Tools/Templates and Add-ins..., then click the Organizer button. Click Close file on one side of the dialog, then click Open File and navigate to your template. Repeat with the other side if necessary.

Valid XHTML 1.1Valid CSSMade on a Macintosh

Quick Links

Updated? Check Mactopia Downloads for the latest updates.

Figure out which v.X update you have.

Other troubleshooting help: Word MVP's FAQ Site.

Troubleshooting Office v.X