Excel 2013 All-in-One For Dummies
Book image
Explore Book Buy On Amazon

After you’ve created a macro in Excel 2013, you don’t necessarily have to re-record it to change the way it behaves. In many cases, you will find it more expedient to change its behavior by simply editing its contents in the Visual Basic Editor.

Note that if the macro you want to edit is stored in your Personal Macro Workbook, you must unhide this workbook before you edit it in the Visual Basic Editor.

To open a macro for editing in the Visual Basic Editor, follow these steps:

Click the View Macros option on the Macros command button on the View tab or press Alt+WMV or Alt+F8.

Click the View Macros option on the Macros command button on the View tab or press Alt+WMV or Alt+F8.

This action opens the Macro dialog box showing all the names of the macros that you’ve defined in the workbook and in your Personal Macro Workbook.

Click the name of the macro that you want to edit in the Macro Name list box and then click the Edit button.

Click the name of the macro that you want to edit in the Macro Name list box and then click the Edit button.

This action opens the Visual Basic Editor with the code for your macro displayed in the Code window unless you select the name of a macro saved in the Personal Macro Workbook and this workbook is still hidden.

In that case, Excel displays an Alert dialog box telling you that you can’t edit a hidden macro and informing you that you need to unhide this workbook. You then need to click OK in the Alert dialog box, press Escape to close the Macro dialog box, and unhide the Personal Macro Workbook.

After you have the lines of code for the macro displayed in the Code window in the Visual Basic Editor, you can edit any of its statements as needed. If you want to obtain a printout of the lines of code in your macro before you begin making changes, choose File→Print on the Visual Basic Editor menu bar or press Ctrl+P.

This action opens a Print – VBAProject dialog box with the Current Module option button selected in the Range section and the Code check box selected in the Print What section so that you can go ahead and click OK to have Excel print all the statements in the macro.

When editing the macro’s commands, remember that you can use the Edit→Undo (Ctrl+Z) command to undo any deletion that you make by mistake.

Edit the statements in the Code window of the Visual Basic Editor as needed.

Edit the statements in the Code window of the Visual Basic Editor as needed.

After you finish editing the macro, you’re ready to return to your spreadsheet, where you can test out the modified macro and make sure that you haven’t added some wacky, unwanted command to the macro or, even worse, crippled it so that it no longer runs at all.

Click the View Microsoft Excel button at the beginning of the Standard toolbar or click the workbook’s minimized button on the Windows taskbar.

Click the View Microsoft Excel button at the beginning of the Standard toolbar or click the workbook’s minimized button on the Windows taskbar.

Select an appropriate or safe place in which to test your modified macro and then run it, either by pressing its shortcut keys or by pressing Alt+F8, clicking it in the Macro list box, and then clicking the Run button.

If something doesn’t work as intended or if the macro doesn’t work at all, you need to return to the Visual Basic Editor and find and correct your error(s). Click the Visual Basic command button on the Developer tab of the Ribbon (Alt+LV) to return to the Visual Basic Editor and have a try at editing the code one more time.

If everything checks out and runs as planned, you need to save your changes as outlined in Step 5.

Click the Save button on the Quick Access toolbar to save the changes to the modified macro if it’s stored as part of the current workbook.

Click the Save button on the Quick Access toolbar to save the changes to the modified macro if it’s stored as part of the current workbook.

If you modified a global macro saved as part of the Personal Macro Workbook, you have to exit Excel in order to save your changes to the macro. When you click the Excel program window’s Close button or press Alt+FX or Alt+F4, Excel displays an alert dialog box asking whether you want to save the changes you made to the personal.xlsb file.

Click the Yes button to save your macro modifications as you close down Excel.

About This Article

This article is from the book:

About the book author:

Greg Harvey, PhD, is President of Mind Over Media and a highly skilled instructor. He has been writing computer books for more than 20 years, and his long list of bestsellers includes all editions of Excel For Dummies, Excel All-in-One For Dummies, and Excel Workbook For Dummies.

This article can be found in the category: