|
In Microsoft® Word, you can use a macro to perform a sequence of
steps. A macro is great for any series of steps that you repeat frequently.
For example, you could create a simple macro to reset a numbered list
to start at 1. You can also create complicated macros that include many
steps.
When should you automate a task using a macro?
Create a macro to save time. You can reduce a number of steps and keystrokes
to one quick action by pressing a key combination or pressing a button
on a toolbar.
Tip: Before you consider a macro, check if Word provides a more
efficient way to speed up your work by using templates, styles, or AutoText.
Methods for creating a macro
- Recording a macro. This is the easy way to create a macro.
Use Word's macro recorder tool to record every action you take. Word
stores the actions as instructions in VBA (Visual Basic® for Applications)
code.
- Writing a macro. You can write the code yourself in VBA.
Word includes a Visual Basic Editor that allows you to do this.
Let's take the easy way and use the macro recorder.
Plan before you record
Before you start recording, make some notes about the actions you want
to take.
Recording a simple macro
- Start the Macro Recorder. On the Tools menu, point to Macro,
and click Record New Macro.

- Complete the fields on the Record Macro dialog box:
- Name the macro. No spaces allowed; use letters and numbers only.
- Select where to store the macro. You can make the macro available
in all documents or restrict the macro to the current document.
- Write a description.
- In Assign macro to, select the way you want to run the macro.
You can click Toolbars or Keyboard. In this case, we'll
click Toolbars to assign the macro to a toolbar button.

- Select a category from the Categories box and point to the
command. Drag the command to a toolbar.

- Rename the button. The default name includes the document name,
the module, and the macro name. This is much too long.
- To give the button a shorter name, right-click the button and type
a new name.
- Click Close in the Customize dialog box.
The macro recorder starts. The cursor turns into a cassette tape,
and the Stop recording toolbar opens.

- Record the actions you want to automate.
In the restart numbering example, we complete the following steps:
- Click the Format menu.
- Click Bullets and Numbering.
- Click the Numbered tab.
- Click Restart numbering.
- When finished, click the Stop button to turn off the recorder.
Running the macro
To run the macro, you can:
- Click the button where you assigned your macro.
- Press the key combination if you assigned a keystroke.
- On the Tools menu, point to Macro, and click Macros.
- Select the macro name, and click Run.
A few tips and warnings
- Saving your macro. The macro isn't saved until you save the
document or template. Word saves the macro in the Normal.DOT template
when you close Word.
To force Word to save the Normal.DOT template immediately:
Press and hold Shift and click the File menu. Click
Save All.
- Getting secure. Word 2003 added a lot of security features
because hackers can do bad things with macros. Take a look at Tools
> Macros > Security for more information. If you want to
run the macros you create, you can't use the highest levels of security.
- Cleaning up. When you record a macro, Word takes your steps
literally. It also records all the parameters in a dialog box, even
if you select only one. So a recorded macro may generate more changes
than you expect.
For details on how to fix your macro, see "How to modify a
recorded macro" on the Word MVP site (included below).
For more info
If you're really excited about creating macros and want to learn more,
check out the Word MVP site:
www.word.mvps.org/FAQs/index.htm
Click the tab for Macros/VBA.

|