To automate a repetitive task, you can quickly create a
macroAn action or a set of actions that you can use to automate tasks. Macros are recorded in the Visual Basic
for Applications programming language.
in Word. You can also use the
Visual Basic EditorAn environment in which you write new and edit existing Visual Basic
for Applications code and procedures. The Visual Basic Editor contains a complete debugging toolset for finding syntax, run-time, and logic problems in your code.
in Microsoft Visual Basic
for Applications to write your own macro script, or to copy all or part of a macro to a new macro.
 | Record a macro |
All the steps that are required to complete the actions that you want your macro to perform are recorded. However, navigation back to the tab to stop recording is not included in the recorded steps.
-
On the Developer tab, under Visual Basic, click Record.

 | If the Developer tab is not available
|
-
On the right side of the ribbon, click
, and then click Ribbon Preferences.
-
Under Customize, select the Developer check box.
-
In the Macro name box, enter a name for the macro.
-
On the Store macro in pop-up menu, do one of the following:
To save the macro | Click |
|---|
In the document that you are creating the macro in | [document name]
(document) |
In all open documents | All Documents (Normal) |
-
Click OK, and then perform the actions that you want to record.
-
On the Developer tab, under Visual Basic, click Stop.
 | Create a macro by using Visual Basic for Applications |
You can use the built-in Visual Basic Editor to create a macro.
-
On the Developer tab, under Visual Basic, click Editor.

 | If the Developer tab is not available
|
-
On the right side of the ribbon, click
, and then click Ribbon Preferences.
-
Under Customize, select the Developer check box.
-
If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.
-
In the code window of the module, type or paste the macro code that you want to use.
-
When you are finished, on the Word menu, click Close and Return to Microsoft Word.
 | Run a macro |
-
On the Developer tab, under Visual Basic, click Macros.

 | If the Developer tab is not available
|
-
On the right side of the ribbon, click
, and then click Ribbon Preferences.
-
Under Customize, select the Developer check box.
-
In the list, click the macro that you want to run, and then click Run.
 | Edit a macro |
To edit a macro, you use the
Visual Basic EditorAn environment in which you write new and edit existing Visual Basic
for Applications code and procedures. The Visual Basic Editor contains a complete debugging toolset for finding syntax, run-time, and logic problems in your code..
-
On the Developer tab, under Visual Basic, click Macros.

 | If the Developer tab is not available
|
-
On the right side of the ribbon, click
, and then click Ribbon Preferences.
-
Under Customize, select the Developer check box.
-
In the list, click the macro that you want to edit, and then click Edit.
The Visual Basic Editor opens.
-
Make the changes that you want.
-
When you are finished, on the Word menu, click Close and Return to Microsoft Word.
 | Copy part of a macro to create another macro |
-
On the Developer tab, under Visual Basic, click Macros.

 | If the Developer tab is not available
|
-
On the right side of the ribbon, click
, and then click Ribbon Preferences.
-
Under Customize, select the Developer check box.
-
In the list, click the macro that you want to copy, and then click Edit.
The Visual Basic Editor opens.
-
In the code window of the Visual Basic Editor, select the lines of the macro that you want to copy.
 | Tip To copy the whole macro, include the Sub and End Sub lines in the selection. |
-
On the Edit menu, click Copy.
-
In the Project box of the code window, click the module where you want to put the code.
-
On the Edit menu, click Paste.
 | Delete a macro |
-
On the Developer tab, under Visual Basic, click Macros.

 | If the Developer tab is not available
|
-
On the right side of the ribbon, click
, and then click Ribbon Preferences.
-
Under Customize, select the Developer check box.
-
In the list, click the macro that you want to delete, and then click Delete.