Excel VBA Shortcut Keys: Open, Edit, and Run Macros

VBA & macros · Updated November 3, 2026

Excel VBA Shortcut Keys: Open, Edit, and Run Macros

The most useful Excel VBA shortcut keys on Windows are Alt+F11 to open or switch to the Visual Basic Editor, Alt+F8 to open the Macro dialog, F5 to run code in the editor, and F8 to step through it line by line. Other shortcuts help you inspect projects, set breakpoints, and find code; the right key depends on whether Excel or the editor currently has keyboard focus.

Quick reference: the essential shortcuts

Excel shortcuts and Visual Basic Editor (VBE) shortcuts serve different purposes. Use the first group from an Excel worksheet; use the second after the editor is active. Laptop function-key settings can affect keys such as F5 and F8.

  • Alt+F11 in Excel: Open the VBE, or switch between Excel and the editor.
  • Alt+F8 in Excel: Open the Macro dialog to run, edit, or delete an available macro.
  • F5 in the VBE: Run the current procedure or continue execution.
  • F8 in the VBE: Execute the next statement in the procedure, stepping into called procedures.
  • Shift+F8 in the VBE: Step over a called procedure rather than entering it.
  • Ctrl+Shift+F8 in the VBE: Step out of the current procedure.
  • F9 in the VBE: Set or remove a breakpoint on the current line.
  • Ctrl+G in the VBE: Show the Immediate window.
  • Ctrl+R in the VBE: Show the Project Explorer.
  • F4 in the VBE: Show the Properties window.

These are Windows shortcuts. On Mac, the Option key is commonly used where Windows uses Alt, but function-key behavior depends on the keyboard and macOS settings. Details and alternatives appear below.

Open the VBA editor and return to Excel

Press Alt+F11 while Excel is active to open the VBE. If it is already open, the same shortcut usually switches focus back to Excel; it does not close the editor or erase code. You can also open it from the ribbon using Developer > Code > Visual Basic. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon, then select Developer.

The editor contains separate code windows for workbook objects, worksheets, and standard modules. In Project Explorer, expand the workbook and double-click an object or module to open its code. A shortcut may appear to do nothing if a dialog is open, another application has focus, or a laptop treats F11 as a media key. Try holding Fn with the key combination, or use the ribbon command to confirm that the editor is available.

Alt+F11 opens the programming environment; it does not itself create a macro. To record a simple sequence of worksheet actions, use View > Macros > Record Macro or Developer > Code > Record Macro. Recording is useful for discovering basic VBA syntax, but recorded code often includes extra selections and may need editing to work reliably with different ranges.

Run, record, and manage macros

In Excel, Alt+F8 opens the Macro dialog. Select a macro and choose Run to execute it, Edit to open its code in the VBE, or Delete to remove it. The dialog shows macros Excel can access in the current context; a macro stored in another workbook or in the Personal Macro Workbook may be listed if that workbook is open. Alt+F8 does not run a macro immediately, so it is a useful way to choose among several procedures.

From inside the VBE, place the cursor in a procedure and press F5 to run it. If the code has a required argument or is not a runnable procedure, F5 may not start it as expected. A typical macro that appears in the Macro dialog is a public Sub procedure in a standard module and has no required arguments. A worksheet event procedure, such as a change event, is triggered by an event rather than selected from the Macro dialog.

Recording and running a macro are different actions. Stopping a recording saves generated code, while running applies an existing macro. Before testing code that changes cells, formatting, or workbook structure, save a copy of the workbook. Excel macros cannot be undone with Ctrl+Z, and a macro can make many changes in a single run. Workbooks containing VBA generally need a macro-enabled format such as .xlsm to preserve their code.

Navigate code and inspect a project

Several VBE shortcuts make it easier to move around without searching the menus. Ctrl+R displays the Project Explorer, where workbook objects and modules are organized. F4 opens the Properties window for the selected object. Ctrl+G opens the Immediate window, which is useful for evaluating expressions or issuing commands while debugging. F2 opens the Object Browser, where you can browse available objects, methods, and properties.

Use Ctrl+F in the VBE to find text, such as a procedure name or a variable reference. Search results depend on the selected scope and search options, so check whether the search is limited to the current procedure, module, or project. When you know the name of a procedure, the procedure list at the top-right of a code window can also help you jump to it.

These tools are especially helpful when a workbook has multiple sheets and modules. For example, if a button runs a procedure that calls another procedure, Project Explorer helps locate the relevant modules, while Find can trace occurrences of a procedure name. The Object Browser can clarify whether a property belongs to a worksheet, range, workbook, or another object instead of relying on guesswork.

Debug code with stepping and breakpoints

When a macro produces an unexpected result, do not rely only on running it repeatedly. In the VBE, F8 executes one statement at a time and highlights the next line. This lets you watch the order of operations and identify the point where a value or selection changes. If the highlighted line calls another procedure, F8 enters that procedure so you can follow its internal steps.

Use Shift+F8 to step over a procedure call. The called procedure still runs, but the editor does not take you through each of its lines. Use Ctrl+Shift+F8 to step out of the current procedure and return to its caller. F5 resumes normal execution from a paused point. These controls are most useful when you already have a specific procedure open and understand which line you want to inspect.

A breakpoint pauses execution before a selected line. Click the line and press F9 to toggle a breakpoint; a marker appears in the editor gutter. Run the procedure with F5, and Excel pauses when it reaches that line. This is quicker than stepping through every statement from the start when the problem occurs later in a routine. To stop a running macro on Windows, Ctrl+Break is the usual interrupt shortcut, although some keyboards require Fn or a different Pause/Break key. In the VBE, Run > Reset stops the current execution state.

While paused, inspect variables in the code or use the Immediate window. A common debugging mistake is to assume that a line has already run because it is highlighted; in step mode, the highlighted statement is generally the next one to execute. Check the status and the current position before drawing conclusions about a variable’s value.

Mac and Excel for the web differences

Excel for Mac supports VBA, but keyboard layouts and function-key settings can change how shortcuts work. Option+F11 is commonly used to open or switch to the Visual Basic Editor, and Option+F8 commonly opens the Macro dialog. On some Macs you must also hold Fn, or change macOS keyboard settings so the top row sends standard function keys. The Developer tab and the Excel menu commands are alternatives when a shortcut is intercepted by macOS or does not behave as expected.

VBE debugging keys such as F5 and F8 may also require Fn on a Mac keyboard. Shortcuts involving Ctrl can differ from those using Command in ordinary Mac applications; do not assume that replacing Ctrl with Command will reproduce every VBE command. If a key combination conflicts with a system shortcut, use the editor menus and check the keyboard settings for that device. Mac Excel supports many VBA projects, but Windows-specific APIs, controls, and automation dependencies may not work on Mac.

Excel for the web does not run, create, or edit VBA macros. A workbook with macros can be opened in the browser, but VBA execution requires the desktop Excel application. If a macro button or procedure is unavailable online, open the file in desktop Excel rather than repeatedly trying browser shortcuts. Office Scripts are a separate automation option for some web-based workflows; they are not VBA and do not use the VBE shortcuts described here.

Choose a shortcut for the task

The quickest shortcut depends on what you are trying to accomplish and where the cursor is. Use this workflow to avoid confusing commands from Excel with commands from the VBE:

  1. To open code: In Excel, press Alt+F11, then select the workbook object or module in Project Explorer.
  2. To run a known macro: In Excel, press Alt+F8, select the macro, and choose Run. If you are already in its procedure in the VBE, use F5.
  3. To understand a failure: Open the procedure, put the cursor at the relevant line, press F9 for a breakpoint, and run it. Use F8 to examine statements around the pause.
  4. To inspect the project: Use Ctrl+R for Project Explorer, F4 for Properties, or F2 for the Object Browser.
  5. To leave a paused run: Use F5 to continue, or Run > Reset in the VBE to stop and reset execution.

Keep in mind that a keyboard shortcut acts on the active window. If Alt+F8 does not show the Macro dialog, first switch back to Excel. If F8 does not step through code, activate a code window in the VBE and make sure execution is paused or a runnable procedure is selected. This focus check solves many apparent shortcut problems.

Common shortcut problems and safe use

If Alt+F11 or Alt+F8 does not work, check these common causes before changing the workbook. First, confirm that the desktop version of Excel is active, not Excel for the web. Second, try Fn with the function key on a laptop. Third, close a modal dialog that may be capturing keystrokes. Finally, verify that the Developer tab or VBE can be reached through the ribbon or menus. Some keyboard utilities and remote desktop setups also remap keys.

A shortcut opening the editor does not mean the macro is safe or enabled. Excel’s macro security settings may block code from an untrusted file. Only enable macros when the workbook and its source are trusted; do not lower security settings simply to make a shortcut work. If you received the file from someone else, ask what the macro does and inspect its code or obtain it from a trusted source.

Use a disposable copy when learning to debug or when testing code that modifies data. Unlike ordinary worksheet edits, macro actions cannot be reversed with Ctrl+Z. For important workbooks, save before running code and confirm that the intended workbook is active. A macro may act on a different open workbook than expected if its code uses the active workbook or active sheet rather than an explicitly named object.

Frequently Asked Questions

What is the shortcut to open VBA in Excel?
On Windows, press Alt+F11 to open or switch to the Visual Basic Editor. If you are using a laptop, Fn may be needed. On Mac, Option+F11 commonly works, subject to function-key settings.

What shortcut opens the Excel Macro dialog?
Press Alt+F8 in desktop Excel for Windows. On Mac, Option+F8 commonly opens it. The dialog lets you select a macro and run, edit, or delete it; it does not immediately execute the selected code.

How do I run VBA code from the editor?
Place the cursor inside a runnable procedure in the VBE and press F5. You can also choose Run > Run Sub/UserForm. If the procedure requires arguments or is an event procedure, it may need to be run through its intended trigger instead.

How do I step through a macro one line at a time?
Press F8 in the VBE to execute the next statement. Shift+F8 steps over a called procedure, while Ctrl+Shift+F8 steps out of the current one. Function-key settings may require Fn.

Can I use VBA shortcuts in Excel for the web?
No. Excel for the web does not run or edit VBA. Open the workbook in desktop Excel to use the Visual Basic Editor and its shortcuts.

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.