Create or run a macro

In Word, you can automate frequently used tasks by creating and running macros. A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically.

To save time on tasks you do often, bundle the steps into a macro. First, you record the macro. Then you can run the macro by clicking a button on the Quick Access Toolbar or pressing a combination of keys. It depends on how you set it up.

Note: If you give a new macro the same name as a built-in macro in Word, the new macro actions will replace the built-in macro. To view a list of built-in macros, click Word Commands in the Macros in list.

In the Macros in list, click the template or document in which you want to store the macro.

To make your macro available in all documents, be sure to click Normal.dotm.

Click Create to open the Visual Basic Editor.

After you open the Visual Basic Editor, you may want more information about working with Visual Basic for Applications. For more information, click Microsoft Visual Basic Help on the Help menu or press F1.

You can record a sequence of actions, or you can write a macro from scratch by entering Visual Basic for Applications code in the Visual Basic Editor.

Note: To work with macros in Office Word 2007, you need to show the Developer tab.

Note: If you give a new macro the same name as a built-in macro in Office Word 2007, the new macro actions will replace the built-in macro. To view a list of built-in macros, on the Developer tab, in the Code group, click Macros. In the Macros in list, click Word Commands.

In the Store macro in box, click the template or document in which you want to store the macro.

Important: To make your macro available in all documents, be sure to click Normal.dotm.

In the Description box, type a description of the macro.

Do one of the following:

Begin recording To begin recording the macro without assigning it to a button on the Quick Access Toolbar or to a shortcut key, click OK.

Create a button To assign the macro to a button on the Quick Access Toolbar, do the following:

Click Button.

Under Customize Quick Access Toolbar, select the document (or all documents) for which you want to add the macro to the Quick Access Toolbar.

Important: To make your macro available in all documents, be sure to click Normal.dotm.

Under Choose commands from dialog box, click the macro that you are recording, and then click Add.

To customize the button, click Modify.

Under Symbol, click the symbol that you want to use for your button.

In the Display name box, type the macro name that you want to display.

Click OK twice to begin recording the macro.

The symbol that you choose is displayed in the Quick Access Toolbar. The name that you type is displayed when you point to the symbol.

Assign a keyboard shortcut To assign the macro to a keyboard shortcut, do the following:

Click Keyboard.

In the Commands box, click the macro that you are recording.

In the Press new shortcut key box, type the key sequence that you want, and then click Assign.

Click Close to begin recording the macro.

Perform the actions that you want to include in the macro.

Note: When you record a macro, you can use the mouse to click commands and options, but not to select text. You must use the keyboard to select text. For more information about selecting text by using the keyboard, see Select text.

Note: If you give a new macro the same name as a built-in macro in Office Word 2007, the new macro actions will replace the built-in macro. To view a list of built-in macros, click Word Commands in the Macros in list.

In the Macros in list, click the template or document in which you want to store the macro.

To make your macro available in all documents, be sure to click Normal.dotm.

Click Create to open the Visual Basic Editor.

After you open the Visual Basic Editor, you may want more information about working with Visual Basic for Applications. For more information, click Microsoft Visual Basic Help on the Help menu or press F1.