Write or record a macro
In Microsoft Office Word, you can automate frequently used tasks by creating macros. A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically.
Typical uses for macros are:
- To speed up routine editing and formatting
- To combine multiple commands - for example, to insert a table with a specific size and borders, and with a specific number of rows and columns
- To make an option in a dialog box more accessible
- To automate a complex series of tasks
You can use the macro recorder to record a sequence of actions, or you can create a macro from scratch by entering Visual Basic for Applications code in the Visual Basic Editor .
Note To work with macros in Office Word, you need to show the Developer
tab.What do you want to do?
Use Visual Basic for Applications
Show the Developer tab
- Click the
Microsoft Office Button
, and then click
Word Options
. - Click
Popular
. - Under
Top options for working with Word
, select theShow Developer tab in the Ribbon
check box.
Use the macro recorder
- On the
Developer
tab, in theCode
group, clickRecord Macro
. - In the
Macro name
box, type a name for the macro.Note If you give a new macro the same name as a built-in macro in Office Word, the new macro actions will replace the built-in macro. To view a list of built-in macros, on the
Developer
tab, in theCode
group, clickMacros
. In theMacros in
list, clickWord Commands
. - In the
Store macro in
box, click the template or document in which you want to store the macro. - In the
Description
box, type a description of the macro. - Do one of the following:
- To begin recording the macro without assigning it to a button on the Quick Access Toolbar or to a shortcut key, click
OK
. - To assign the macro to 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. - Under
Choose commands from
dialog box, click the macro that you are recording, and then clickAdd
. - Click
OK
to begin recording the macro.
- Click
- 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 clickAssign
. - Click
Close
to begin recording the macro.
- Click
- To begin recording the macro without assigning it to a button on the Quick Access Toolbar or to a shortcut key, click
- 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.
- To stop recording your actions, click
Stop Recording
in theCode
group.
Use Visual Basic for Applications
- On the
Developer
tab, in theCode
group, clickMacros
. - In the Macro name box, type a name for the macro.
Note If you give a new macro the same name as a built-in macro in Office Word, the new macro actions will replace the built-in macro. To view a list of built-in macros, click
Word Commands
in theMacros in
list. - In the
Macros in
list, click the template or document in which you want to store the macro. - Click
Create
to open the Visual Basic Editor.