Recording a macro

A macro, in Office applications, is a synonym for VBA code. In Excel, we can record almost any action we perform (such as mouse clicks and typing), which in turn is registered as VBA code. This can come in handy when we need to discover properties and methods related to an object. Let us now have a look at some ways you can record a macro in Excel. There are two options:

  1. Recording a macro from the status bar.
  2. Recording from the Developer tab.

Option 1 — Recording a macro from the status bar

From the status bar, click on the Record Macro button. If the button is not visible, right-click on the status bar and from the pop-up menu, choose the Macro Recording option, as shown in the following screenshot:

Option 2 — Recording from the Developer tab

Now that you know how to record a macro from the status bar, let us check another option. This option requires that you activate the Developer tab. In order to activate it, assuming it is not active yet, follow these steps:

  1. Go to File | Excel Options | Customize Ribbon.
  2. Under Main Tabs check the Developer checkbox, as shown in the following screenshot :

  3. Next, activate the Developer tab and click on Record Macro, as shown in the following screenshot:

  4. Once the macro recording process starts, you will be prompted to enter some basic information about the macro such as the macro name, the shortcut key, location where the macro should be stored, and its description. The following screenshot shows these options filled out:

  5. Once the macro has been recorded, you can access its container module by pressing, simultaneously, the Alt + F11 keys. Alternatively, you can click on the Visual Basic button in the Developer tab. This button is to the left of the Record Macro button introduced previously. This will open the Visual Basic Editor (VBE), where all the VBA code is kept.

    The VBE is the tool we use to create, modify, and maintain any code we write or record. The following screenshot shows the VBE window with the project explorer, properties, and code window visible:

  6. If upon opening the VBE, the VBA project explorer window is not visible, then follow these steps:
    1. Go to View | Project Explorer.
    2. Alternatively, press the Ctrl + R keys simultaneously.
  7. If, on the other hand, the VBA project explorer is visible, but the code window is not, you can choose which code window to show.
  8. Suppose you are interested in the content of the module you’ve recorded from the project explorer window, follow these step to show the module window:
    1. Click on View | Code.
    2. Alternatively, press F7.

Leave a Reply

Your email address will not be published. Required fields are marked *