Excel VBA Keyboard Shortcut: Open, Run, and Assign

VBA & macros · Updated November 19, 2026

In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor (VBE), where you can view and edit VBA code. To run a macro from Excel, press Alt+F8, choose the macro, and select Run; you can also assign a shortcut to a particular macro.

The main Excel VBA shortcuts

There is no single keyboard shortcut that does everything related to VBA. The right key combination depends on whether you want to open the code editor, start a macro, or control code while it is running. These shortcuts apply to desktop Excel on Windows:

  • Alt+F11: Open or switch to the Visual Basic Editor.
  • Alt+F8: Open the Macro dialog, where you can choose and run an available macro or open its options.
  • F5 in the Visual Basic Editor: Run the current procedure when the cursor is inside it.
  • F8 in the Visual Basic Editor: Step through a procedure one line at a time, which is useful for debugging.

These commands have different effects. Alt+F11 opens a coding environment; it does not run the code. Alt+F8 is a convenient way to run a macro without assigning a permanent shortcut. F5 runs code from inside the editor, so it is not the same as pressing F5 while working in a worksheet.

What Alt+F11 opens

The Visual Basic Editor is Excel’s desktop environment for working with Visual Basic for Applications, or VBA. It contains the code modules and workbook objects associated with an open file. From there, you can write procedures, inspect existing code, and use debugging tools. The editor is separate from the worksheet grid, but it works with the open Excel workbook.

When the editor opens, the Project Explorer may show the current workbook and its sheets. If you do not see that pane, press Ctrl+R in the editor to show the Project Explorer. A macro you want to run from Excel is commonly stored in a standard module, which you can add from the editor using Insert > Module. Workbook and worksheet objects also have code areas, but those are generally used for event code, such as code that responds when a sheet changes.

To return to Excel, press Alt+F11 again or switch windows. The editor and workbook remain open together; closing the editor window does not by itself delete the code.

Run a macro from Excel

For an occasional macro, the Macro dialog is often easier than remembering a custom key combination. Press Alt+F8, select the macro name, and choose Run. The dialog lists macros that Excel can run from the available open workbooks, subject to their location and visibility. If the list is empty, the macro may not be in an open workbook, may be stored as private or event code, or macros may be blocked.

You can also use the Developer tab. If it is hidden, enable it on Windows through File > Options > Customize Ribbon, select the Developer check box, and click OK. Then choose Developer > Macros to reach the macro list. The tab is just another route; it does not change how the macro works.

Before running an unfamiliar macro, find out what it does. A macro can change cells, delete sheets, modify files, or perform other actions under your account. The fact that a macro appears in the list is not proof that it is safe.

Assign a keyboard shortcut to a macro

To give a frequently used macro a shortcut in Windows Excel, first make sure it is available in an open workbook. Press Alt+F8, select the macro, and click Options. Enter a letter in the shortcut-key box, then confirm the dialog. Excel assigns a Ctrl-based combination: a lowercase letter uses Ctrl+letter, while an uppercase letter uses Ctrl+Shift+letter. For example, entering an uppercase M assigns Ctrl+Shift+M.

  1. Open the workbook containing the macro, then press Alt+F8.
  2. Select the macro and click Options.
  3. Enter a letter, choose a descriptive shortcut description if desired, and click OK.
  4. Close the Macro dialog and use the new key combination in Excel while the macro is available.

Choose a combination that will not disrupt a shortcut you rely on. A macro shortcut can take precedence over Excel’s normal Ctrl+letter shortcut while the workbook that defines it is open. If you store a macro in the Personal Macro Workbook, it is available across workbooks during that Excel session, so its shortcut can affect your usual workflow more broadly. You can return to the macro’s Options dialog to change or remove its assigned key.

A small example and where to put it

This harmless example displays a message, so it is useful for confirming that a macro runs. In the VBE, choose Insert > Module and paste the procedure into the new standard module. Save the workbook before running it.

Option Explicit

Public Sub ShowVbaShortcutMessage()
    Dim prompt As String

    ' Set a short message to display.
    prompt = "VBA is running."
    MsgBox prompt, vbInformation, "Excel VBA"
End Sub

Return to Excel and press Alt+F8. Select ShowVbaShortcutMessage and click Run. Once you have confirmed that it works, you can assign it a shortcut through the Options steps above. This example uses a public procedure with no arguments in a standard module, a straightforward structure for a macro launched from the Macro dialog or its assigned shortcut.

For a macro-enabled workbook, save in the Excel Macro-Enabled Workbook (*.xlsm) format. A regular .xlsx file does not store VBA project code; Excel warns that the macros will be removed if you save a workbook containing them in that format.

Windows, Mac, and Excel for the web

On a Mac, the shortcut to open the Visual Basic Editor is generally Option+F11. Depending on the keyboard and macOS function-key settings, you may need to press Fn+Option+F11. If the key combination is intercepted by a system or keyboard setting, use Excel’s menus or check the function-key setting rather than assuming that the Windows shortcut will work unchanged. Menu labels and the macro-management experience can differ between Mac and Windows.

Excel for the web does not let you create, edit, or run VBA macros. If a workbook contains VBA, use the Open in Desktop App option and work in the desktop version of Excel. This matters when a file opens in a browser even though it contains a macro: a keyboard shortcut cannot make the browser run VBA.

Macro security and saving your work

Excel applies security controls to macros because VBA can make substantial changes or interact with files and other resources. A workbook downloaded from the internet or received by email may open with its macros disabled. Do not enable macros just to make a shortcut work unless you trust the source and understand the purpose of the code. If a trusted workplace file is blocked, follow your organization’s approved process instead of weakening security settings globally.

Before running a macro that edits data, save a separate copy of the workbook. VBA actions generally cannot be reversed with Ctrl+Z; Excel’s Undo history does not reliably roll back a macro’s changes. A backup gives you a practical recovery option if code has an unexpected effect. For important data, test on a copy with a small sample first.

Common shortcut problems

  • Alt+F11 does nothing: Check that you are using desktop Excel, not Excel for the web. On a laptop, try the Fn key if function-key settings require it, and check whether another application or system shortcut is capturing the combination.
  • The macro is missing from Alt+F8: Confirm that the workbook is open and that the procedure is a public macro in a standard module. A worksheet event procedure or a procedure declared Private is not normally offered as a regular macro to run from that list.
  • The assigned shortcut does not run the macro: Make sure the workbook containing the assignment is open, check the letter and whether Shift is required, and confirm that macros are permitted. Also check for another open workbook that assigns the same shortcut.
  • The code opens but F5 fails: Put the cursor inside a runnable procedure and check for compile errors. F5 is an editor command, not a replacement for correcting missing code or references.

These checks help distinguish a shortcut problem from a macro problem. If Alt+F11 opens the editor but the macro will not run, the editor shortcut is working; investigate the macro’s availability, security status, or code instead.

Frequently Asked Questions

What is the shortcut to open VBA in Excel?

In desktop Excel for Windows, press Alt+F11 to open the Visual Basic Editor. On a Mac, use Option+F11, or Fn+Option+F11 if your keyboard requires the Fn key.

What is the shortcut to run a VBA macro?

Press Alt+F8 in Excel to open the Macro dialog, select a macro, and choose Run. If you have assigned a shortcut to that macro, you can use its Ctrl-based key combination instead.

Can I run a VBA macro in Excel for the web?

No. Excel for the web does not create, edit, or run VBA macros. Open the workbook in desktop Excel to use its VBA code.

Why can’t I undo a macro with Ctrl+Z?

Running VBA usually clears or bypasses Excel’s normal Undo history, so Ctrl+Z cannot be relied on to reverse its changes. Save a copy before running a macro that edits a workbook.

Does an Excel VBA shortcut work on every workbook?

No. A shortcut assigned to a macro is available when the workbook containing that macro is open. A macro stored in the Personal Macro Workbook can be available more broadly, but its shortcut may also conflict with normal Excel commands.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.