Recording a Macro

You can create a macro by recording it with the macro recorder, writing it in WordBasic, or both. For many macros, even complex ones, a good technique is to start by recording as much of the macro as possible and then finish by writing the parts of the macro that can't be recorded.

Starting the Recording

To begin recording a macro, choose the Macro command from the Tools menu and then choose the Record button in the Macro dialog box, or simply double-click "REC" on the status bar. Word displays the Record Macro dialog box, in which you can name, describe, and assign the macro you are about to record.

Word provides two ways to identify macros: the macro name and its description text. Although you may be tempted to accept the macro name that Word proposes, and get on with recording your macro, it's a good idea to get into the habit of giving meaningful names to macros right away. A macro with a descriptive name is easy to identify. Macro names cannot include spaces, commas, or periods. If you want to include two or more words together in a macro name, you can begin each word with a capital letter to make the name easy to read. For example, "TransposeCharacters" or "OpenSalesReport" are readable macro names. If you assign a macro to a toolbar button, the macro name is displayed in a ToolTip when the mouse pointer is positioned over the toolbar button. When a macro name is displayed in a ToolTip, a space is placed before capital letters; for example, the ToolTip for a macro named "OpenSalesReport" would be "Open Sales Report."

It's also worth taking the time to write a short description in the Description box. As you accumulate macros over time, you may find it difficult to remember what each one does. A macro description provides a helpful reminder. If you assign a macro to a menu or to a toolbar button, its description appears in the status bar when you select the menu item or position the mouse pointer over the toolbar button. A macro description can be up to 255 characters long, although only about 100 characters appear on most status bars (the length of the status bar depends on screen resolution).

By default, macros you record are stored in the Normal template. If a different template is attached to the active document, you can also store a macro in that template. For more information on storing macros in different templates, see "Macros and Templates" later in this chapter.

Û To start recording the BoldItalic macro

The BoldItalic macro, a macro that applies bold and italic formatting to a selection, is the practice macro you will create in this chapter. Of course, you can easily apply bold and italic separately by pressing Ctrl+B and Ctrl+I (Windows) or command+B and command+I (Macintosh). But if you often format text as bold italic, it's convenient to have a quick way to apply both formats at once.

1. Do one of the following:

2. In the Record Macro Name box, type BoldItalic.

3. In the Description box, type Applies bold and italic formatting to selected text.

The next step is to assign the BoldItalic macro to a shortcut key. This procedure is described in the next section.

Assigning the Macro

Even before you begin to record your macro, you can assign it to a menu, toolbar, or shortcut key. You could wait until after you've recorded it, but if you assign the macro right away, you can try it out after you've finished recording. Also, fewer steps are needed to assign it at this point. If the macro you're recording doesn't work out, you can easily delete it; any assignments you've made for it are removed also.

There are advantages and disadvantages to each kind of assignment. A menu item provides the highest visibility, but menus have limited space. A toolbar button is slightly more accessible than a menu item, but its purpose is less obvious. A shortcut key is hidden, but provides the quickest access.

Û To assign the BoldItalic macro to a shortcut key

Because the BoldItalic macro is a short macro that must run quickly to be worth running at all, it makes sense to assign it to a shortcut key for quick access.

1. In the Record Macro dialog box, choose the Keyboard button.

Word displays the Customize dialog box with the BoldItalic macro name selected.

2. Position the insertion point in the Press New Shortcut Key box, and do one of the following:

3. Choose the Assign button.

By default, this duplicate shortcut key was assigned to the Bold command. When you choose the Assign button, the shortcut key is assigned to the BoldItalic macro. Later, if you remove this assignment, the shortcut key will be reassigned to the Bold command.

4. Choose the Close button.

Now you're ready to take the actions you want the macro recorder to record. This procedure is described in the next section.

Recording the Macro Actions

When you've named your macro and assigned it, you're ready to begin recording. After you close the Record Macro dialog box, the macro recorder records every action you take in Word until you turn the recorder off.

When the macro recorder is on, the Macro Record toolbar is displayed. It contains the Stop and Pause buttons, which you can use to stop and pause the macro recorder. If you click the Pause button to pause the recorder — perhaps to arrange something for your macro that you didn't set up in advance — the button remains in the down position. You can click it again to resume recording.

When the macro recorder is on, a recorder graphic attaches to the mouse pointer when it is positioned over a document window. In addition, the abbreviation "REC" (for "record") is highlighted in the status bar. You can double-click it to stop recording. (When the macro recorder is not on, you can double-click "REC" to start recording.)

When you stop recording, the Macro Record toolbar disappears automatically.

Here are a few things to be aware of when you're recording macros:

Û To record the actions of the BoldItalic macro

1. From the Format menu, choose Font. In the Font dialog box, select Bold Italic in the Font Style list, and then choose OK.

2. Click the Stop button on the Macro Record toolbar.