Record or run a macro

In Microsoft Office Word 2007, 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.

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 record a sequence of actions, or you can write a macro from scratch by entering Visual Basic for Applications (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) code in the Visual Basic Editor (Visual Basic Editor: An 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.).

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

What do you want to do?


Show the Developer tab

  1. Click the Microsoft Office Button Button image, and then click Word Options.
  1. Click Popular.
  2. Under Top options for working with Word, select the Show Developer tab in the Ribbon check box.

 Note   The Ribbon is a component of the Microsoft Office Fluent user interface.

Top of Page Top of Page

Record a macro

On the Developer tab, in the Code group, click Record Macro.

  1. 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:
    1. Click Button.
    2. 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.

  1. Under Choose commands from dialog box, click the macro that you are recording, and then click Add.
  2. To customize the button, click Modify.
  3. Under Symbol, click the symbol that you want to use for your button.
  4. In the Display name box, type the macro name that you want to display.
  5. 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:
  1. Click Keyboard.
  2. In the Commands box, click the macro that you are recording.
  3. In the Press new shortcut key box, type the key sequence that you want, and then click Assign.
  4. Click Close to begin recording the macro.
  1. 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.

  1. To stop recording your actions, click Stop Recording in the Code group.

Change the keyboard shortcut for a macro

  1. Click the Microsoft Office Button Button image, and then click Word Options.
  1. Click Customize.
  2. Next to Keyboard shortcuts, click Customize.
  3. In the Categories list, click Macros.
  4. In the Macros list, click the macro that you want to change.
  5. In the Press new shortcut key box, type the key combination that you want to choose.
  6. Check the Current keys box to make sure that you aren't assigning a key combination that you already use to perform a different task.
  7. In the Save changes in list, click the option that matches where you want to run your macro.

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

  1. Click Close.

Top of Page Top of Page

Run a macro

  1. On the Developer tab, in the Code group, click Macros.

Code group on the Developer tab

  1. In the list under Macro name, click the macro that you want to run.
  2. Click Run.

Top of Page Top of Page

Write a macro from scratch

  1. On the Developer tab, in the Code group, click Macros.

Code group on the Developer tab

  1. 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 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.

  1. In the Macros in list, click the template (template: A file or files that contain the structure and tools for shaping such elements as the style and page layout of finished files. For example, Word templates can shape a single document, and FrontPage templates can shape an entire Web site.) or document in which you want to store the macro.

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

  1. 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.

Top of Page Top of Page

See it in action

Watch these videos to see how to create, edit, and run a macro.

Enable the Developer tab and prepare to record a macro

Word Options dialog box

Play Demo Demo button

See how to enable the Developer tab, prepare a macro, assign a button, and begin recording

Record, pause, save, and run

Recording macro in Word

Play Demo Demo button

See how to record a macro while pausing and resuming, and then save and run the results.

Edit the macro

Microsoft Visual Basic Editor

Play Demo Demo button

Watch as a macro is edited in Microsoft Visual Basic and saved.

Assign a button or keyboard shortcut

Customize keyboard dialog box

Play Demo Demo button

Assign a button or a keyboard shortcut to an existing macro.

Top of Page Top of Page

 
 
Applies to:
Word 2007