To run a VBA macro in Excel, press Alt + F8 to open the Macro dialog, select the macro, and click Run. If you want a one-key shortcut, assign a shortcut letter in that same dialog (Options), or press Alt + F11 to open the VBA Editor and press F5 to run the procedure the cursor is in. The fastest repeatable method is a button or a Quick Access Toolbar icon, both covered below.

What You'll Need

  • Excel on Windows or Mac (the shortcuts differ slightly; both are covered).
  • A workbook saved as .xlsm (macro-enabled) if you want the code to persist. A normal .xlsx file strips macros on save.
  • Macros enabled for the file. Excel shows a yellow security bar when macros are blocked; click Enable Content only for files you trust.
  • Access to the Developer tab (optional but useful). Enable it via File > Options > Customize Ribbon and tick Developer, or on Mac via Excel > Preferences > Ribbon & Toolbar.

Step-by-Step

  1. Open the workbook that contains the macro. If the code lives in your Personal Macro Workbook, any open workbook will do.
  2. Enable macros if prompted. Look for the security bar under the ribbon and click Enable Content. If the bar is missing, check File > Info > Enable Content (labels vary slightly by version).
  3. Open the Macro dialog with Alt + F8. This is the universal shortcut and works on Windows and Mac. A list of available macros appears.
  4. Select the macro by name. Use the dropdown at the bottom to switch between All Open Workbooks and a specific workbook if the list looks empty.
  5. Click Run. The macro executes immediately. If it is a Function rather than a Sub, it will not appear here; functions are called from cells or from other code.
  6. To assign a keyboard shortcut: in the Macro dialog, select the macro and click Options. Type a letter in the Shortcut key box. Excel assigns Ctrl + Shift + that letter automatically (for example, typing q gives Ctrl+Shift+Q). Click OK. The shortcut now works in that workbook.
  7. To run from the VBA Editor: press Alt + F11 (Windows) or Option + F11 (Mac) to open the editor. Click inside the procedure you want and press F5. To run a single line for testing, use F8 to step through.
  8. To add a button: on the Developer tab, click Insert > Button (Form Control), draw it on the sheet, then pick the macro in the dialog that appears. Clicking the button runs it from then on.
  9. To add a Quick Access Toolbar icon: right-click the macro in the Macro dialog and choose Add to Quick Access Toolbar if available, or use File > Options > Quick Access Toolbar and select Macros from the dropdown to add it manually.
  10. Save the workbook as .xlsm. Use File > Save As and choose Excel Macro-Enabled Workbook. Otherwise the shortcut and code disappear next time you open the file.

Common Mistakes

  • Saving as .xlsx. Excel warns you and then discards the macros. Always use .xlsm for files with code.
  • Expecting the shortcut to work in every workbook. A shortcut assigned in one workbook only fires while that workbook is open and active.
  • Using Ctrl + a letter alone. Excel reserves most plain Ctrl combinations. The Macro Options dialog forces Ctrl+Shift+letter for this reason.
  • Looking for a Function in the Macro list. Functions do not appear in Alt + F8. Call them from a cell (for example =MyFunction(A1)) or from a Sub.
  • Ignoring the security bar. If macros are disabled, Alt + F8 shows an empty list or the macro silently does nothing.
  • Running code with the wrong sheet active. Many macros act on ActiveSheet; select the intended sheet before running.

Tips

  • Name macros descriptively (for example FormatReport) so you can find them quickly in the dialog.
  • Store reusable macros in the Personal Macro Workbook so the shortcuts are available in every workbook you open.
  • Use F8 to step through unfamiliar code line by line before running it on real data.
  • Keep a backup copy of the workbook before running a macro that deletes rows, sheets or formatting.
  • On Mac, some Windows-only VBA features (such as certain file dialog calls) behave differently; test before relying on them.
  • If you share the file, note that recipients must enable macros themselves; you cannot force it.

Troubleshooting

If the macro does not run, work through these in order:

  1. Check the security bar. If macros are blocked, click Enable Content. If the file came from the internet, Windows may mark it as blocked; right-click the file in File Explorer, open Properties, and tick Unblock if present, then reopen.
  2. Confirm the file is .xlsm. If it is .xlsx, the code is already gone; you will need to re-add it and save correctly.
  3. Check the Trust Center. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and confirm macros are not set to Disable all macros without notification. Only change this if you understand the risk; do not lower security for files you do not trust.
  4. Look for a compile error. Press Alt + F11, then use Debug > Compile VBAProject. Fix any highlighted line before running.
  5. Check the macro is in a standard module. Code in ThisWorkbook or a sheet module may not appear in Alt + F8 unless it is a Public Sub.
  6. Restart Excel. A hung macro or a crashed editor session often clears on restart.
  7. Test in a copy. If the macro errors on real data, run it on a duplicate workbook to see the error message without risking your original.

Frequently Asked Questions

What is the single fastest shortcut to run a macro?

Alt + F8, then Enter. It opens the Macro dialog with the last-used macro selected, so two keystrokes run it.

Can I run a macro with one key press?

Yes, by assigning a shortcut in the Macro Options dialog (Ctrl+Shift+letter) or by adding a Form Control button to the sheet.

Why does Alt + F8 show no macros?

Usually because macros are disabled, the file is .xlsx, or the code is a Function rather than a Sub. Check the security bar and the file extension first.

Do shortcuts work on Excel for Mac?

Yes, with small differences: Alt + F8 becomes Option + F8, and the VBA Editor opens with Option + F11. Assigned Ctrl+Shift+letter shortcuts work the same way.

Can I run a macro automatically when the workbook opens?

Yes, by naming a Public Sub Auto_Open or placing code in the Workbook_Open event in ThisWorkbook. Macros must still be enabled by the user.

Does running a macro affect other open workbooks?

Only if the code references them. Most macros act on the active workbook or a named sheet, so select the right workbook before running.