Excel VBA: How to Start a Macro (Step-by-Step)
In this article
To start a VBA macro in Excel, open the workbook that contains it, enable macros when prompted, then press Alt+F8 (Windows) or Fn+Option+F8 (Mac), select the macro name, and click Run. If you want the macro to fire from a button or a keyboard shortcut instead, you can assign it to a shape or record a shortcut key. The steps below cover both the quick manual run and the more permanent ways to launch a macro, plus what to check when nothing happens.
What You'll Need
- Excel for Windows or Mac (the menu labels below are for the desktop app; Excel for the web cannot run VBA macros at all).
- A workbook saved as .xlsm (macro-enabled) or .xlsb. A standard .xlsx file cannot store macros.
- Macro security set to allow the file. If macros are disabled, the macro will not appear in the list or will not run.
- Optional: the Developer tab visible if you plan to assign macros to buttons or check settings. Right-click the ribbon and choose Customize the Ribbon, then tick Developer in the right-hand list.
Step-by-Step
- Open the correct workbook. Macros live inside a specific file, so open the .xlsm or .xlsb workbook that contains the macro you want to run. If you are not sure which file it is, ask whoever supplied it; macros are not stored in your personal Excel settings by default.
- Enable macros if Excel asks. A yellow security bar may appear under the ribbon saying macros have been disabled. Click Enable Content. If the bar does not appear and the macro list is empty, check Trust Center settings: File > Options > Trust Center > Trust Center Settings > Macro Settings (on Mac: Excel > Preferences > Security). The exact wording varies slightly by version and region. Only enable macros in files you trust, because VBA can run any command your account can.
- Open the macro list. On Windows press Alt+F8. On Mac press Fn+Option+F8 (or Option+F8 on keyboards where F8 is a media key). You can also use the ribbon: Developer tab > Macros. The Macro dialog box lists every public macro in open workbooks.
- Pick the macro. In the Macros in dropdown, choose This Workbook or the specific workbook name to narrow the list. Click a macro name to select it. Names that start with Auto_Open or Workbook_Open are event macros and normally run automatically when the file opens; they can still be run manually from this list.
- Run it. Click Run (or press Enter). The dialog closes and the macro executes. If the macro is long-running, Excel may appear frozen; wait for it to finish rather than clicking repeatedly.
- Run it from a button (optional). On the Developer tab choose Insert > Button (Form Control), draw the button on the sheet, and in the Assign Macro dialog pick the macro and click OK. You can then rename the button text by right-clicking it. This is the most reliable way for other people to start a macro without knowing the shortcut.
- Run it from a keyboard shortcut (optional). In the Macro dialog, select the macro and click Options. Type a letter in the shortcut box; Excel assigns Ctrl+that letter (lowercase letter uses Ctrl, uppercase uses Ctrl+Shift). Click OK. Note that this shortcut is stored in the workbook, so it travels with the file.
- Save the workbook. If you added a button or shortcut, save as .xlsm so the changes persist. Closing without saving discards the assignment.
Common Mistakes
- Running a macro from the wrong workbook. The Macro dialog shows macros from all open workbooks. If two files have a macro with the same name, you can run the wrong one. Always set the Macros in dropdown to the file you mean.
- Saving as .xlsx. Excel warns you that macros cannot be saved in a macro-free format. If you click Yes to keep .xlsx, the macro code is stripped out. Choose Save As > Excel Macro-Enabled Workbook.
- Blocking macros by policy. Files downloaded from the internet or email are often marked with a blocked flag. Excel may show a red security warning instead of the yellow bar. Right-click the file in File Explorer, choose Properties, and tick Unblock if you trust the source. On Mac, use the Trust Center equivalent in Preferences.
- Assuming a shortcut is global. Ctrl+letter shortcuts assigned in the Macro Options dialog only work while that workbook is open. They do not become system-wide hotkeys.
- Expecting macros in Excel for the web. The browser version cannot run VBA. Open the file in the desktop app instead.
Tips
- Give macros descriptive names without spaces (for example RefreshReport, not Refresh Report). Spaces force you to remember odd naming and can confuse the dialog.
- Use the Developer tab > Record Macro to capture a sequence of actions, then edit the generated code in the Visual Basic Editor (Alt+F11 on Windows, Fn+Option+F11 on Mac).
- Keep a backup copy of any macro-enabled workbook before editing code, because a broken macro can prevent the file from opening cleanly.
- If you share the file, add a button rather than relying on Alt+F8; most users will not know the shortcut.
- Test macros on a copy of the data first. A macro that deletes rows or overwrites cells cannot be undone with Ctrl+Z in most cases.
Troubleshooting
If the macro does not appear in the list, first confirm the file is .xlsm or .xlsb and that you opened the right workbook. Then check that macros are enabled: look for the yellow security bar or the red blocked-content warning. If the file came from another computer, unblock it as described above and reopen it.
If the macro appears but does nothing when you click Run, check whether it is designed to act on the active sheet or a specific sheet name. A macro that refers to a sheet that no longer exists will usually stop with an error dialog; read the message and note the line it highlights. Press Debug in that dialog to open the Visual Basic Editor at the failing line.
If Excel shows a "macros have been disabled" message and the Enable Content button is greyed out, the file may be in a trusted location that is configured to disable macros, or an administrator policy may block them. In that case, contact your IT administrator; do not try to bypass the policy.
If a button you added does nothing, right-click it and choose Assign Macro to confirm the correct macro is attached. If you renamed the macro in the code, the button still points to the old name and must be reassigned.
If the workbook crashes or hangs when the macro runs, close Excel, reopen the file with macros disabled (hold Shift while opening on Windows), and inspect the code before running it again. Holding Shift suppresses automatic macros such as Workbook_Open, which is useful when one of those is causing the problem.
Frequently Asked Questions
Why can't I see the Developer tab?
It is hidden by default. Right-click the ribbon, choose Customize the Ribbon, and tick Developer in the list on the right. On Mac, open Excel > Preferences and look for the Ribbon settings.
Can I run a macro without enabling all macros?
Yes. Enable macros only for the specific file by clicking Enable Content on the security bar, or add the file's folder to Trust Center trusted locations if you control the machine. Avoid setting "Enable all macros" globally.
Do macros run in Excel for the web or mobile?
No. VBA macros require the desktop version of Excel on Windows or Mac. The web and mobile apps can open macro-enabled files but cannot execute the code.
How do I stop a macro that is already running?
Press Esc or Ctrl+Break (Windows). On Mac, press Command+Period. If Excel is unresponsive, you may need to force-quit and reopen the file with macros disabled.
Where are macros stored?
In the workbook itself, in the VBA project. They are not saved in a separate file unless you export the module from the Visual Basic Editor (File > Export File).
Can I make a macro start automatically when the file opens?
Yes, by naming it Auto_Open or placing code in the ThisWorkbook module's Workbook_Open event. Both run when the workbook opens, provided macros are enabled. Remember that users who disable macros will not trigger it.