Tuesday, February 12, 2019

Create, run, edit, or delete a macro

Create, run, edit, or delete a macro

To save time on tasks you do often, you can record the steps of those tasks as a macro. Then, when you want to perform one of those recorded tasks, you can activate the macro to perform the steps for you.

Word

In Word 2016 for Mac, you can create a macro that has a keyboard shortcut, run a macro, and delete a macro that you no longer need.

  1. Click View > Macros > Record Macro.

    On the View tab, click Macro, and then click Record Macro to begin creating a macro.
  2. Type a name for the macro, or accept the default that Word provides.

    Enter a name for your macro in Macro name, or accept the generic name provided by Word.
  3. To use this macro in any new documents you create, verify that All Documents (Normal) is selected in the Store macro in list.

  4. Click Keyboard to assign a key combination to your macro.

    Word displays the Customize Keyboard dialog box.

  5. Type a combination of keys in the Press new keyboard shortcut box.

    Word displays the command or macro already assigned to a key combination, if any, after you press the combination.

    When you press a key combination, Word displays the command or action currently assigned to that key combination, if any.

  6. If the key combination that you chose is already assigned, delete it from the Press new keyboard shortcut box, and then choose a new key combination.

    Go on to the next step after you have found an unassigned key combination.

    Word identifies when you have pressed a key combination that is not yet assigned to a command or macro.
  7. To use this keyboard shortcut in any new documents, be sure Normal.dotm, the global template, is selected in the Save changes in list.

    Select Normal.dotm to make a macro available for use in new documents that you create.
  8. Click Assign.

  9. When you are ready to record the macro, click OK.

  10. Click the commands or press the keys for each step in the task.

    Word records your clicks and keystrokes, but it does not record text that you select with the mouse. To select text while recording a macro, use the keyboard.

  11. To stop recording, click View > Macros > Stop Recording.

    Click Stop Recording on the Macros menu to stop recording a macro.

To run a macro, press the keyboard shortcut assigned to it, or run the macro from the Macros list.

  1. Click View > Macros > View Macros.

    Click View Macros to view and edit macros associated with the current document.
  2. In the list under Macro name, select the macro that you want to run.

  3. Click Run.

    After selecting a macro under Macro name, click Run to run it.

  1. Click View > Macros > View Macros.

    Click View Macros to view and edit macros associated with the current document.
  2. Verify that the location specified by Macros in includes the location of the macro that you want to delete.

    Select the location of the macros that you want to view from the Macros in list.

    The list will include the document that is open in the current window, as well as the global template and Word commands.

  3. Under Macro name, select the macro that you want to delete, and then click the minus sign below the list.

    Select the macro that you want to delete, and then click the minus sign under the list.
  4. When Word asks to confirm that you want to delete the macro, click Yes.

Excel

In Excel 2016 for Mac, you can create a macro that has a keyboard shortcut, run a macro, and delete a macro that you no longer need.

When you record a macro, the macro recorder records all the steps required to complete the actions that you want your macro to perform. These steps can include typing text or numbers, clicking cells or commands on the ribbon or on menus, formatting, selecting cells, rows, or columns, and dragging your mouse to select cells on your spreadsheet.

Note: The commands for recording, creating, and deleting macros, as well as other advanced features, are also available on the Developer tab on the Ribbon. For more information about using the Developer tab, see Use the Developer tab to create or delete a macro in Excel 2016 for Mac.

  1. Select Tools > Macro > Record New.

    Select Tools, then Macro, then Record New Macro

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

    Enter a macro name, location, and shortcut key

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

  4. Select a location for the macro from the drop-down list.

    To save the macro

    Click

    In the document that you are creating macro in

    This Workbook

    In all open documents

    New Workbook

    To be available whenever you use Excel

    Personal Macro Workbook

  5. (Optional) Add a description of your macro.

  6. When you are ready to record, click OK.

  7. Click the commands or press the keys for each step in the task.

  8. To stop recording, select Tools > Macro > Stop Recording. (This step will not be recorded in your macro.)

    Select Stop Recording

To run a macro, press the keyboard shortcut assigned to it, or run the macro from the Macros dialog.

  1. On the View tab, click View Macros.

  2. Click Macros in the pop up menu and select This Workbook.

  3. Select your macro from the list and click Run.

    Excel for Mac Macros dialog

  1. Select Tools > Macro > Macros.

    Select Macro and then select Macros

  2. Select the macro to delete, and then press the minus sign.

    Select macro name and then select minus sign

  3. A confirmation message will appear. Click Yes to confirm the deletion.

    Confirm deletion

You can also delete a macro from the Developer tab.

  1. On the Developer tab, click Macros.

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

    Select a macro and click the minus sign to delete it

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.

When you 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)

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

  5. On the Developer tab, under Visual Basic, click Stop.

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.

  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.

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.

  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.

  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 use Visual Basic for Applications to create a macro in PowerPoint.

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.

  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.

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.

  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.

  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.

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 macro workbook is located at Users/ username/Library/Application Support/ Microsoft/Office/Excel.

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

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

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.

  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.

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.

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

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

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

  6. On the File menu, click Save As.

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

  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.

  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.

No comments:

Post a Comment