Lesson 9 of 60 – Running a Macro
15%

Running a Macro

After creating or recording a Macro, the next step is to run the Macro. Running a macro tells Excel to execute the instructions stored inside that macro.

Note: Before running a macro, make sure the workbook contains the required macro and that Excel allows the macro to run according to its security settings.

1. What Does Running a Macro Mean?

Running a macro means executing the VBA instructions stored inside the macro.

When you run a macro, Excel performs the actions defined in the macro automatically.

2. Why Run a Macro?

The main purpose of running a macro is to automate a task that would otherwise require manual steps.

For example, a macro can format a report, calculate values, or process data automatically.

3. Open a Workbook Containing a Macro

First, open the Excel workbook that contains the macro you want to run.

For practice, you can use the macro created in the previous lesson.

4. Check the Developer Tab

Click the Developer tab on the Excel Ribbon.

The Developer Tab provides several tools for working with macros, including the Macros command.

5. Click the Macros Button

In the Developer Tab, click the Macros button.

Excel will open the Macro dialog box.

6. Macro Dialog Box

The Macro dialog box displays macros that are available to run.

You can select a macro from the list and then choose an available action such as Run or Edit.

7. Select the Macro

Select the macro that you want to execute.

For example, if you created a macro named:

FormatStudentData

select FormatStudentData from the list.

8. Click Run

After selecting the macro, click the Run button.

Excel will execute the instructions contained in the selected macro.

9. Observe the Worksheet

After running the macro, observe the worksheet.

The actions recorded or programmed inside the macro should be performed automatically.

For example, formatting may be applied to the selected cells.

10. Running a Recorded Macro

A recorded macro can be run in the same way as other macros.

For example, if you previously recorded a macro that makes headings bold, running it can apply that formatting again.

11. Run Macro Using Developer Tab

One common method of running a macro is:

  1. Click Developer.
  2. Click Macros.
  3. Select the macro.
  4. Click Run.

This method provides a clear way to view and select available macros.

12. Run Macro from the View Tab

Excel also provides access to the Macro dialog through the View tab.

You can use the Macros command available under the View tab to open the Macro dialog and run a macro.

13. Run Macro with a Keyboard Shortcut

A macro can be assigned a keyboard shortcut when the macro is created or configured.

After assigning a shortcut, you can use that shortcut to run the macro more quickly.

14. Run Macro from a Button

A macro can also be assigned to a worksheet button.

When the user clicks the button, the assigned macro runs.

This is useful when creating user-friendly Excel applications.

15. Run Macro from a Shape

A macro can also be assigned to a shape inserted into an Excel worksheet.

For example, a shape labeled Generate Report can be connected to a macro that creates or formats a report.

16. Running a Macro Multiple Times

A macro can generally be run multiple times when the same automation is required.

For example, if a macro formats a report, you can run it whenever the same formatting operation is needed.

17. Macro Execution

When a macro runs, Excel executes the VBA statements contained in the macro's procedure.

The exact result depends on what instructions were recorded or written in the VBA code.

18. Example of Running a Formatting Macro

Suppose you created a macro that makes the heading of a student marksheet bold.

When you run the macro, Excel executes the formatting instructions and the heading becomes bold.

Sub FormatStudentData()

    Range("A1:B1").Select
    Selection.Font.Bold = True

End Sub

19. Macro and Active Workbook

Some recorded macros operate on the workbook, worksheet, or cells that were involved when the macro was created.

Therefore, you should understand which workbook and worksheet the macro is designed to work with.

20. Macro Security and Running Macros

Excel security settings can affect whether a macro is allowed to run.

If macros are blocked, you may see a security notification when opening a macro-enabled workbook.

Only enable macros when the workbook and its code are trusted.

21. Macro-Enabled Workbook

If you want to keep VBA macros in an Excel workbook, the workbook should be saved in a macro-enabled format such as .xlsm.

This allows the workbook to store VBA macro code.

22. What Happens When a Macro Runs?

When you run a macro, Excel executes its VBA instructions in sequence.

Depending on the macro, it may:

  • Enter values
  • Format cells
  • Copy data
  • Calculate values
  • Create reports
  • Work with worksheets

23. Run Macro After Editing

A macro can be edited in the VBA Editor.

After making changes to the VBA code, you can return to Excel and run the macro to test the updated behavior.

24. Testing a Macro

It is important to test a macro after creating or editing it.

Check whether the macro performs the intended actions and produces the expected result.

Use sample data while learning and testing.

25. Simple Steps to Run a Macro

  1. Open the macro-enabled workbook.
  2. Click the Developer Tab.
  3. Click Macros.
  4. Select the required macro.
  5. Click Run.
  6. Observe the result.

26. Common Reason a Macro Does Not Run

One common reason is that macros are disabled by Excel's security settings.

Other possibilities include an incorrect workbook, an unavailable macro, or an error in the VBA code.

27. Practical Example

Suppose you recorded a macro named:

FormatStudentData

The macro makes the heading bold and applies borders to a student marks table.

Open the Macros dialog, select FormatStudentData, and click Run. Excel performs the recorded formatting operations.

28. Different Ways to Run a Macro

Method Basic Use
Developer → Macros Select and run a macro.
View → Macros Open the Macro dialog.
Keyboard Shortcut Quickly execute an assigned macro.
Worksheet Button Run a macro by clicking a button.
Shape Run a macro from an assigned shape.

29. Complete Macro Running Workflow

A simple macro execution workflow is:

  1. Create or record a macro.
  2. Save the workbook in a suitable macro-enabled format.
  3. Open the workbook when required.
  4. Open the Macro dialog.
  5. Select the macro.
  6. Run the macro.
  7. Check the result.

30. Complete Understanding of Running a Macro

Running a macro means executing the VBA instructions stored inside the macro. Excel provides several ways to run a macro, including the Developer Tab, View Tab, keyboard shortcuts, worksheet buttons, and shapes.

The most basic method for beginners is to open the Macro dialog, select the required macro, and click Run.

Always test your macros carefully and only enable macros from workbooks that you trust.

📌 Key Points

  • Running a macro executes its stored VBA instructions.
  • The Developer Tab provides access to the Macros command.
  • Select a macro from the Macro dialog and click Run.
  • Macros can also be assigned to keyboard shortcuts.
  • Macros can be assigned to buttons and shapes.
  • Macro security settings can affect macro execution.
  • Macro-enabled workbooks commonly use the .xlsm format.
  • Always test macros before using them with important data.

🧠 Quick Quiz

Question: What should you click after selecting a macro in the Macro dialog to execute it?