Excel Macro Editor Basics

I like to think of an editor as a tool that enhances your work and offers guidance. This holds whether the editor is a real person or a built-in tool like the Excel macro editor. One benefit of Microsoft’s editor is that it is a teaching tool. In this tutorial, I’ll show how to edit a macro in Excel and other editor features.

Why Use the Excel Macro Editor?

Apart from offering guidance, the editor also allows you to:

  • add comments to your macro
  • modify macros
  • combine modules
  • move or copy macros

Where are Excel Macros Located?

People are usually elated after learning how to record and run an Excel macro for the first time. But then the question comes up as to where the macros are stored. They are neatly hidden behind a toolbar button.

  1. Click the View tab.
  2. To the far right, click the small triangle Excel downward triangle. below the Macros button label.
Excel macro toolbar button.Pin
Fig. 1 – Toolbar Macro button and options
  1. From the button menu, select View Macros.
  2. A Macro dialog box appears with 4 areas.
Excel macro dialog box.Pin
Fig. 2 – Excel Macro Dialog box

[A] A listing of your macros.
[B] A drop-down menu showing the location of macros.
[C] The description of the highlighted macro if provided.
[D] Actions you can take on the highlighted macro.

In the screenshot above (Fig. 2 – [A]), I have one macro. It’s the one I created from the previous tutorial. The first part of the listing shows that this macro is attached to PERSONAL.XSLB or my “personal workbook.” You can use macros in your personal workbook in any of your Excel spreadsheets.

In contrast, if I created a macro called Set_Address_Columns that was attached to a specific spreadsheet, it would only show when I was using that macro-enabled spreadsheet. These macros do not have a location identifier in front.

Macro attached to workbook.Pin
Fig. 3 – Macro attached to current worksheet

If you don’t see your macro, try changing your location as shown in Fig. 2 [B].

How to View Macros in Excel

To view the macro contents, you need to click the Edit button even if you don’t plan to make any changes. The macro editor can be a bit intimidating at first until you get the basics.

Macro editor with code snippet.Pin
Fig. 4 – Macro editor with my code

When you open the editor, you’ll see several panels based on your settings. The one we’ll start with is on the right. It shows the VBA code for the macro. VBA stands for Visual Basic Application. Excel’s Macro Recorder automatically generated the code you see here. I didn’t enter any of the macro code you see on the right.

If you look at the right side, you may notice some patterns.

[A] Each macro starts with a Sub reference followed by the macro name we assigned. This stands for a Subroutine or subprocedure. You’ll also note the macro ends with a End Sub command. Both these items display in blue.

[B] Next, we have a series of lines in green, starting with an apostrophe. These are comments and are used to explain the macro. You could delete them, and the macro would still run. They don’t impact the macro, so it wouldn’t work if you changed the Keyboard Shortcut to something else.

You can add your own comments by starting a line with an apostrophe . This can be useful when making changes to a macro or documenting it for others.

[C] The lines are in black are the macro’s code and include references to actions, properties, and objects. This section is great for teaching as you can see how the steps you performed with the macro recorder got translated. You may recall from my earlier tutorial; I was deleting specific columns I no longer needed, such as A, D, J, K, L, and N.

[D] This is the Explorer. This panel can also be a bit intimidating. The key things to remember are that your macro code shows in the items marked as Module. You’ll also note a slight shading on Module1 under my (PERSONAL.XLSB) section. This shading indicates that is the code I’m viewing on the right.

You can double-click other Modules to see their code.

If you don’t see the Project panel, you can reveal it from the View and selecting Project Explorer.

How to Change Macro Shortcut Key or Description

Some of the earliest changes people like to do are to change either the shortcut key or macro description. Even though there is a reference to the shortcut in Figure 4, it’s a comment. That means if you changed the reference here, it wouldn’t work. Comments do not affect your code.

If you go back to the initial Macro dialog, you’ll see a button on the bottom labeled Options…. Clicking that button will open the Macro Options dialog. From here, you can change the Shortcut Key [A] or Description [B].

Options dialog for changing shortcut and description.Pin
Fig. 5 – Shortcut and Description options

Use the Editor as a Learning Tool

One of the features I appreciate about the editor is how I can learn more about how macros are constructed and VBA. Using the macro recorder, you can record simple macros and see how the code displays in the editor.

A simple macro you might try is to set up is one that puts in column headings. Then see how the editor recorded these entries. Then, for simple changes, you can edit the code directly.

The code editor also includes Microsoft’s IntelliSense, which offers code completion, suggestions, and formatting when you type code. For example, if I type a period . followed by my first letter s, IntelliSense will filter the list to show valid entries starting with that letter. It also uses the desired camelCase formating.

Intellisense code suggestions.Pin
Fig. 6- IntelliSense suggestions

Next Steps

Once you get acquainted with the macro editor, you can try adding more complex code. This article is meant to be a high-level look at the editor. However, if you wish to learn more about macros and VBA, I’d suggest the free 3-part video series from Excel Campus.