Create, run, edit, or delete a macro

Which Office program are you using?


Word

To automate a repetitive task, you can quickly create a macro (macro: An 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 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.) 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:

ShowRecord 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

ShowIf 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.
  1. In the Macro name box, enter a name for the macro.
  2. 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.

ShowCreate 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

ShowIf 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.
  1. If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.
  2. In the code window of the module, type or paste the macro code that you want to use.
  3. When you are finished, on the Word menu, click Close and Return to Microsoft Word.

ShowRun a macro

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

Word Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to run, and then click Run.

ShowEdit a macro

To edit a macro, you use 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.).

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

Word Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to edit, and then click Edit.

The Visual Basic Editor opens.

  1. Make the changes that you want.
  2. When you are finished, on the Word menu, click Close and Return to Microsoft Word.

ShowCopy part of a macro to create another macro

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

Word Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to copy, and then click Edit.

The Visual Basic Editor opens.

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

  1. On the Edit menu, click Copy.
  2. In the Project box of the code window, click the module where you want to put the code.
  3. On the Edit menu, click Paste.

ShowDelete a macro

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

Word Developer tab, Visual Basic group

ShowIf 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.
  1. 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 (macro: An 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 PowerPoint.

Do any of the following:

ShowCreate 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

ShowIf 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.
  1. If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.
  2. In the code window of the module, type or paste the macro code that you want to use.
  3. When you are finished, on the PowerPoint menu, click Close and Return to Microsoft PowerPoint.

ShowRun a macro

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

PowerPoint Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to run, and then click Run.

ShowEdit a macro

To edit a macro, you use 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.).

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

PowerPoint Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to edit, and then click Edit.

The Visual Basic Editor opens.

  1. Make the changes that you want.
  2. When you are finished, on the PowerPoint menu, click Close and Return to Microsoft PowerPoint.

ShowCopy part of a macro to create another macro

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

PowerPoint Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to copy, and then click Edit.

The Visual Basic Editor opens.

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

  1. On the Edit menu, click Copy.
  2. In the Project box of the code window, click the module where you want to put the code.
  3. On the Edit menu, click Paste.

ShowDelete a macro

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

PowerPoint Developer tab, Visual Basic group

ShowIf 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.
  1. 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 (macro: An 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 Excel. You can also use 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.) 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:

ShowRecord 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

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

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

ShowCreate 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

ShowIf 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.
  1. If you need to insert a module, in the Visual Basic Editor, on the Insert menu, click Module.
  2. In the code window of the module, type or paste the macro code that you want to use.
  3. When you are finished, on the Excel menu, click Close and Return to Microsoft Excel.

ShowRun a macro

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

Excel Developer tab, Visual Basic group

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

ShowEdit a macro

To edit a macro, you use 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.).

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

Excel Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to edit, and then click Edit.

The Visual Basic Editor opens.

  1. Make the changes that you want.
  2. When you are finished, on the Excel menu, click Close and Return to Microsoft Excel.

ShowConfigure 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

ShowIf 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.
  1. In the Macro name box, type Auto_Open.
  2. 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.

ShowCopy part of a macro to create another macro

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

Excel Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to copy, and then click Edit.

The Visual Basic Editor opens.

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

  1. On the Edit menu, click Copy.
  2. In the Project box of the code window, click the module where you want to put the code.
  3. On the Edit menu, click Paste.

ShowDelete a macro

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

Excel Developer tab, Visual Basic group

ShowIf 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.
  1. In the list, click the macro that you want to delete, and then click Delete.

 
 
Applies to:
Excel for Mac 2011, PowerPoint for Mac 2011, Word for Mac 2011