(Legacy) Microsoft Word 2007: Creating Macros

Last Updated

This article is based on legacy software.

A macro is a shortcut for performing a series of actions and is useful for automating complex or repetitive tasks. Macros are helpful if work is being shared with someone else, because it is easier to explain how to use a shortcut than it is to explain several steps. For a macro to be worthwhile, the series of actions you wish to accomplish must be consistent.

When creating a macro, planning can be very helpful. Knowing specifically what you want the macro to accomplish in what order can save a lot of time, editing, and frustration. When the macro is saved, the information is stored as a part of the current template and will be available for all documents based on that template. You can also copy macros to documents based on other templates. For more information on tips for advanced macros and how to run, suspend, or delete macros, refer to Working with Macros.

Macro Tips

As you are creating a macro, you will be requested to assign a name to the macro and to indicate where it will be stored. The following guidelines and tips can help you make the best decision.

Naming a Macro

Macro names must:

  • begin with a letter
  • contain no spaces
  • contain no unusual characters (e.g., @, %, &, ^) 
  • have the appropriate name from the following list to run automatically:
     AutoExecThe macro runs when Word is openedAutoExitThe macro runs when you exit WordAutoOpenThe macro runs when you open a documentAutoNewThe macro runs when you create a new documentAutoCloseThe macro runs when you close the current document

Saving a Macro

A macro is saved as part of a template. If you want the macro available whenever you use Word, the macro should be saved as part of the normal.dotx template. However, if the use of the macro is limited to specific types of documents and you have a template for that type of document, it should be stored in that template.

Assigning Macros

While it is not required to assign a macro to a second location, doing so can make the macro easier to use and save more time. Depending on your personal style of working with Word, you may want to assign the macro to a keystroke combination or the Quick Access toolbar. You can assign the macro to both if you want.

Recording Notes

Macros can be created by recording keystrokes (not mouse actions like selecting text) or by writing the macro using the Visual Basic programming language. This document focuses on macros that can be created through the recording method.

WARNING: If you are working with a multi-layer dialog box (one with tabs at the top), only the changes on the current tab are recorded when you click OK. If you want to record changes on more than one layer, you will need to access the dialog box once for each layer, clicking OK as you complete the changes on that layer.

Accessing the Record New Macro Command

To access the Record New Macro command, you will first need to display the Developer command tab on the Ribbon.

  1. From the OFFICE BUTTON office button , click WORD OPTIONS word options
    The Word Options dialog box appears. 
    word options

  2. From the Categories list, select Popular

  3. In the Top options for working with Word section, select Show Developer tab in the Ribbon

  4. Click OK
    The Developer command tab appears on the Ribbon.

  5. From the Ribbon, select the Developer tab 
    The commands for macros are available.

  6. To record a new macro, from the Code group, click RECORD MACRO record macro
    The Record Macro dialog box appears.

Creating & Recording a New Macro

The Record New Macro command of Word creates macros using the Record Macro dialog box. Using this dialog box, you will name, describe, and assign the storage and access locations of the macro(s) you create.

  1. Access the Record Macro dialog box 
    record macro

  2. In the Macro name text box, type the name for the new macro
    For information on naming conventions, refer to Naming a Macro.

  3. (Optional) In the Description text box, type a short narrative description for the macro

  4. From the Store macro in pull-down list, select the appropriate option
    NOTE: For more information, refer to Saving a Macro.

  5. (Optional) Assign the macro to a button or keyboard combination

  6. Click OK
    Recording of the macro begins: any action you perform within Word will be saved as a part of this macro.

  7. Perform the activity that you want the macro to accomplish

  8. When done, in the Code group, click STOP RECORDING stop recording
    The macro will be saved as part of the template you chose.

  9. Continue with Running a Macro

Assigning Macros to Additional Locations

The following instructions assume that you are assigning the macro to either a keyboard combination or a toolbar as part of the creating process (step 6 of Creating & Recording a New Macro).

Selecting Keyboard Combinations

Many keyboard combinations are already assigned to menu choices and dialog boxes. Below are the potential keyboard combinations you could use for a macro. It is often simply trial-and-error to locate the combination that will work for you.

NOTE: After typing the keyboard combination, a message will appear showing the assignment of the combination.

  • [Alt] + [Ctrl] + character
  • [Alt] + [Shift] + character
  • [Alt] + [Shift] + [Ctrl] + character
  • [Ctrl] + [Shift] + character

Assigning a Keyboard Combination

The following directions show you how to assign your new macro to a keyboard combination before recording is finished.

  1. Access the Record Macro dialog box
    record macro

  2. Under Assign macro to, click KEYBOARD keyboard
    The Customize Keyboard dialog box appears.
    customize keyboard

  3. With your insertion point in the Press new shortcut key text box, press the keyboard combination that you want to use to execute the macro
    NOTE: The shortcut will be displayed in the text box. If there is an action currently associated with the shortcut, it appears below the Current keys scroll list. If you do not want to override the shortcut's original function, delete the shortcut from the text box and press another combination.

  4. Click ASSIGN
    Your shortcut key appears in the Current keys scroll list.

  5. Click CLOSE

  6. To finish creating the macro, continue with step 7 of Creating & Recording a New Macro

Assigning to a Button

If your macro will be used frequently, you may choose to assign it to a button available on the Quick Access toolbar.

  1. Access the Record Macro dialog box

  2. In the Macro name text box, type a name for your macro

  3. Under Assign macro to, click BUTTON button
    The Word Options dialog box appears. 
    word options

  4. From the Categories list, select Customize

  5. From the Customize Quick Access Toolbar pull-down list, select whether you would like this button to appear in all documents or only the current document 
    NOTE: If you choose to modify the toolbar in only the current document, the options available in all documents will disappear from the list of current toolbar commands. They will still appear on the toolbar, however.

  6. From the list of available macros, select the desired macro

  7. Click ADD >> 
    The macro appears in the list of buttons available on the Quick Access toolbar.

  8. Click OK
    The Word Options dialog box closes. Recording of your macro has begun.

  9. To finish creating the macro, continue with step 7 of Creating & Recording a New Macro

  10. To change the icon for the button,
    1. On the Quick Access toolbar, right click the button ยป select Customize Quick Access Toolbar...
      The Word Options dialog box appears.
    2. From the list of existing buttons on the right, select the macro button
      NOTE: If the macro button was added only to the current document, For [this document] must be selected in the Customize Quick Access Toolbar pull-down list for the button to be available.
    3. Click MODIFY...
      The Modify Button dialog box appears.
      modify button
    4. From the Symbol list, select the desired icon
    5. (Optional) To change the name of the button which appears in the ScreenTip, in the Display name text box, type the new name
    6. Click OK
    7. Click OK
      The button takes the appearance of the selected icon.