Create, run, edit, or delete a macro

Which Office program are you using?

Word

PowerPoint

Excel

Word

To automate a repetitive task, you can quickly create a macro in Word. You can also use the Visual Basic Editor 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.

Do any of the following:

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.

  1. On the Developer tab, under Visual Basic, click Record.

    Word Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the Macro name box, enter a name for the macro.

  3. 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)

  1. Click OK, and then perform the actions that you want to record.

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

  1. On the Developer tab, under Visual Basic, click Editor.

    Word Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.

  3. In the code window of the module, type or paste the macro code that you want to use.

  4. When you are finished, on the Word menu, click Close and Return to Microsoft Word.

Run a macro

  1. On the Developer tab, under Visual Basic, click Macros.

    Word Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. 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 Editor.

  1. On the Developer tab, under Visual Basic, click Macros.

    Word Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to edit, and then click Edit.

    The Visual Basic Editor opens.

  3. Make the changes that you want.

  4. When you are finished, on the Word menu, click Close and Return to Microsoft Word.

Copy part of a macro to create another macro

  1. On the Developer tab, under Visual Basic, click Macros.

    Word Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to copy, and then click Edit.

    The Visual Basic Editor opens.

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

  4. On the Edit menu, click Copy.

  5. In the Project box of the code window, click the module where you want to put the code.

  6. On the Edit menu, click Paste.

Delete a macro

  1. On the Developer tab, under Visual Basic, click Macros.

    Word Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to delete, and then click Delete.

PowerPoint

To automate a repetitive task, you can quickly create a macro in PowerPoint.

Do any of the following:

Create a macro by using Visual Basic for Applications

You can use the built-in Visual Basic Editor to create a macro.

  1. On the Developer tab, under Visual Basic, click Editor.

    PowerPoint Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.

  3. In the code window of the module, type or paste the macro code that you want to use.

  4. When you are finished, on the PowerPoint menu, click Close and Return to Microsoft PowerPoint.

Run a macro

  1. On the Developer tab, under Visual Basic, click Macros.

    PowerPoint Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. 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 Editor.

  1. On the Developer tab, under Visual Basic, click Macros.

    PowerPoint Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to edit, and then click Edit.

    The Visual Basic Editor opens.

  3. Make the changes that you want.

  4. When you are finished, on the PowerPoint menu, click Close and Return to Microsoft PowerPoint.

Copy part of a macro to create another macro

  1. On the Developer tab, under Visual Basic, click Macros.

    PowerPoint Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to copy, and then click Edit.

    The Visual Basic Editor opens.

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

  4. On the Edit menu, click Copy.

  5. In the Project box of the code window, click the module where you want to put the code.

  6. On the Edit menu, click Paste.

Delete a macro

  1. On the Developer tab, under Visual Basic, click Macros.

    PowerPoint Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to delete, and then click Delete.

Excel

To automate a repetitive task, you can quickly create a macro in Excel. You can also use the Visual Basic Editor 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.

Do any of the following:

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.

  1. On the Developer tab, under Visual Basic, click Record.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the Macro name box, enter a name for the macro.

    Tip   To create a keyboard shortcut for the macro, type a letter in the Option+Cmd+ box.

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

This Workbook

In all open documents

New Workbook

To be available whenever you use Excel

Personal Macro Workbook

The personal marco workbook is located at Users/ username/Library/Application Support/ Microsoft/Office/Excel.

  1. Click OK, and then perform the actions that you want to record.

  2. On the Developer tab, under Visual Basic, click Record again.

Create a macro by using Visual Basic for Applications

You can use the built-in Visual Basic Editor to create a macro.

  1. On the Developer tab, under Visual Basic, click Editor.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.

  3. In the code window of the module, type or paste the macro code that you want to use.

  4. When you are finished, on the Excel menu, click Close and Return to Microsoft Excel.

Run a macro

  1. On the Developer tab, under Visual Basic, click Macros.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to run, and then click Run.

    Tip   To run a macro by using a keyboard shortcut, press OPTION + COMMAND+the letter you typed when you created the keyboard shortcut.

Edit a macro

To edit a macro, you use the Visual Basic Editor.

  1. On the Developer tab, under Visual Basic, click Macros.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to edit, and then click Edit.

    The Visual Basic Editor opens.

  3. Make the changes that you want.

  4. When you are finished, on the Excel menu, click Close and Return to Microsoft Excel.

Configure a macro to run automatically when a workbook is opened

After you complete this procedure, the macro will run whenever you open the workbook that contains the macro.

  1. On the Developer tab, under Visual Basic, click Record.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the Macro name box, type Auto_Open.

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

This Workbook

In all open documents

New Workbook

To be available whenever you use Excel

Personal Macro Workbook

  1. Click OK, and then perform the actions that you want to record.

  2. On the Developer tab, under Visual Basic, click Record again.

  3. On the File menu, click Save As.

  4. On the Format pop-up menu, click Excel Macro-Enabled Workbook (.xlsm), and then click Save.

Copy part of a macro to create another macro

  1. On the Developer tab, under Visual Basic, click Macros.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to copy, and then click Edit.

    The Visual Basic Editor opens.

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

  4. On the Edit menu, click Copy.

  5. In the Project box of the code window, click the module where you want to put the code.

  6. On the Edit menu, click Paste.

Delete a macro

  1. On the Developer tab, under Visual Basic, click Macros.

    Excel Developer tab, Visual Basic group

    If the Developer tab is not available

    1. On the right side of the ribbon, click Action pop-up menu, and then click Ribbon Preferences.

    2. Under Customize, select the Developer check box.

  2. In the list, click the macro that you want to delete, and then click Delete.

Applies To: Word for Mac 2011



Was this information helpful?

Yes No

How can we improve it?

255 characters remaining

To protect your privacy, please do not include contact information in your feedback. Review our privacy policy.

Thank you for your feedback!

Support resources

Change language