Datasheet

Book IX
Chapter 1
Recording and
Using Macros
Using Auto Macros
567
Actually, with a little more VBA knowledge, you can also remove the
With and End With commands and substitute just the following:
Selection.Font.SmallCaps = True
Using Auto Macros
An auto macro is a macro that runs automatically whenever some key event
happens, such as when Word starts or when a document closes. Word recog-
nizes auto macros by their names. For example, a macro named AutoNew
automatically runs when you create a new document from a template, and
a macro named AutoClose automatically runs when you close a document.
To create an auto macro, you simply create a macro by using one of the
following special macro names:
AutoExec: Runs when Word starts. Store it in the Normal.dotm template.
AutoExit: Runs when Word exits. Store it in the Normal.dotm template.
AutoNew: Runs whenever a new document is created by using the tem-
plate that contains the AutoNew macro.
AutoOpen: Runs whenever an existing document opens. You can create
an AutoOpen macro in the
Normal.dotm template or in the template
that’s attached to the document. Or both.
AutoClose: Runs whenever an open document closes. This macro can
reside in
Normal.dotm or in the template attached to the document.
You can prevent any auto macro from executing by holding down the Shift
key while performing the action that otherwise triggers the macro. For exam-
ple, holding down the Shift key while creating a new document prevents the
AutoNew macro from running.
50_040584 bk09ch01.qxp 12/28/06 9:28 PM Page 567