In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic for Applications (VBA) editor. On a Mac, press Option+F11; depending on your keyboard settings, you may also need to hold Fn. To open Excel’s list of available macros rather than the editor, press Alt+F8 on Windows.
What the Excel VBA shortcut opens
Alt+F11 switches from the Excel worksheet to the Visual Basic Editor, usually called the VBE. This is the separate window where you can view, write, and edit VBA code associated with workbooks, add-ins, or your personal macro workbook. Pressing the shortcut does not itself create or run a macro, and it does not change the contents of your cells.
The editor contains a Project Explorer, which lists open VBA projects, and a code window for the selected module or object. If those panels are not visible, use the editor’s View menu to display them. The VBE may open behind Excel or show an existing code window, depending on what was open previously; that is normal. Press Alt+F11 again to switch back to Excel.
A frequent point of confusion is the difference between opening the editor and opening the macro list. Alt+F11 opens the place where VBA code is edited. Alt+F8 opens Excel’s Macro dialog, where you can choose a macro to run or manage macros. Use the shortcut that matches the task rather than expecting either one to do both.
Windows shortcuts for the editor and macros
These are the most useful keyboard shortcuts when working with VBA in desktop Excel on Windows:
- Alt+F11: Open or switch to the Visual Basic Editor.
- Alt+F8: Open Excel’s Macro dialog to view and run eligible macros.
- F5 in the VBE: Run the procedure in which the cursor is positioned, when it is runnable.
- Ctrl+S: Save the workbook or project. In the VBE, saving the project saves changes to the workbook that contains it.
F5 is not the usual shortcut for running a macro from the worksheet: it is used in the editor. For a macro that is already saved in a workbook, Alt+F8 is the straightforward way to select and run it from Excel. A macro can also be attached to a worksheet button or assigned a keyboard shortcut, which can be convenient for a repeated task.
Using the shortcut on a Mac or in Excel for the web
Excel for Mac supports VBA, but its keyboard layout and function-key settings differ from Windows. The usual editor shortcut is Option+F11. On a Mac keyboard where the top-row keys control brightness, volume, or other hardware functions, hold Fn as well, or adjust the keyboard’s function-key setting. A shortcut may also be affected by macOS or another utility that has claimed the same key combination.
Excel for the web does not create, edit, or run VBA macros. If Alt+F11 or Option+F11 is pressed while using Excel in a browser, it will not open the desktop VBA editor. Open the workbook in the desktop Excel application to work with VBA. A workbook containing VBA can be stored or viewed online, but that does not make its VBA code runnable in the browser.
Some Excel ribbon labels and settings differ between Windows and Mac. If a Mac shortcut is unavailable or behaves differently on your setup, use the ribbon’s Developer tab and look for the Visual Basic command. On Windows, the same command is available at Developer > Visual Basic. The keyboard shortcut is simply the quicker route to that editor.
How to show the Developer tab
You do not need the Developer tab to use Alt+F11, but it provides visible controls for Visual Basic, macros, and other developer tools. If the tab is missing in Excel for Microsoft 365 on Windows, enable it through the ribbon settings:
- Choose File > Options.
- Select Customize Ribbon.
- Under Main Tabs, select the Developer check box.
- Choose OK. The Developer tab should now appear on the ribbon.
On a Mac, open Excel’s ribbon and toolbar customization settings and enable Developer there; the route and wording can vary slightly across Mac releases. Once visible, choose Developer > Visual Basic to open the editor without a keyboard shortcut, or choose Developer > Macros to see the macro list. These ribbon commands are useful when function keys are inconvenient or a shortcut is intercepted.
What happens when you open the VBE
VBA code belongs to a project, not just to the visible worksheet. In the Project Explorer, a workbook project typically includes objects for the workbook and its worksheets, along with folders such as Modules. A standard macro that you want to select from Alt+F8 is commonly placed in a standard module. Worksheet event code, by contrast, belongs in that worksheet’s code module because it responds to events such as a cell change.
To add a standard module, select the relevant workbook project in the VBE and choose Insert > Module. The new code window is where you can type a procedure. For example, this small macro displays a message rather than changing worksheet data:
Sub ShowMessage()
' Display a simple message in Excel.
Dim message As String
message = "VBA is ready."
MsgBox message
End Sub
To try it, save a copy of the workbook first, add the code to a standard module, then return to Excel and open Alt+F8. Select ShowMessage and choose Run. In the VBE, you can also place the cursor inside the procedure and press F5. This example has no cell or file side effects; real macros may edit, delete, or overwrite data, so inspect unfamiliar code before running it.
Running and assigning a macro shortcut
Alt+F8 lists macros that Excel can run in the current context. The list may include macros in the active workbook, other open workbooks, or the personal macro workbook, depending on the dialog’s scope selection and the macro’s visibility. A procedure generally needs to be a public, parameter-free Sub in a standard module to appear as a normal selectable macro. Code that is private, requires arguments, or is an event procedure may not appear there.
If you run the same macro often, Excel lets you assign it a keyboard shortcut. Open Developer > Macros or press Alt+F8, select the macro, and choose Options if that button is available. Excel’s Macro Options dialog can assign a Ctrl-based shortcut, with Shift available to form a different combination. Choose carefully: an assigned shortcut can take precedence over a built-in Excel shortcut while the macro workbook is open. The assignment is associated with the workbook containing the macro, so it may not be available when that workbook is closed.
Assigning a macro shortcut is different from changing Alt+F11. Alt+F11 is the standard command to open the editor; the Macro Options dialog assigns a key to a particular macro. If you only need to inspect or edit code, use Alt+F11. If you want to launch a routine directly from a worksheet, consider a macro shortcut or a clearly labeled button.
Why Alt+F11 may not work
If the editor does not appear, first check whether you are using desktop Excel rather than Excel for the web. Then try the Developer tab’s Visual Basic command. If that works, the issue is likely the keyboard or shortcut handling rather than the VBA editor itself. Common causes include a laptop’s Fn-key mode, an external keyboard setting, a macOS shortcut conflict, or another application capturing the combination.
- Try Fn+Alt+F11 on a Windows laptop if its function keys are assigned to hardware controls.
- On a Mac, try Fn+Option+F11 or check the keyboard’s function-key setting.
- Confirm Excel is the active application and not a browser tab or another program.
- If Excel opens the editor but no code is visible, use Project Explorer to select the right workbook and module.
- If the Macro dialog is empty, check that the workbook contains a runnable macro and that the macro is not hidden by its scope or procedure type.
Macro security is a separate issue. A security warning or blocked macro may prevent code from running, but it does not mean Alt+F11 is the wrong editor shortcut. Organizations can also manage macro policies centrally, so a setting may be unavailable to change. Follow your organization’s rules rather than trying to bypass them.
Saving VBA code and protecting your workbook
An ordinary .xlsx workbook cannot store VBA project code. If you add a macro and save the file as .xlsx, Excel warns that the project will be removed if you continue in that format. To retain workbook macros, save a copy as an Excel Macro-Enabled Workbook (.xlsm). Excel binary workbooks (.xlsb) and Excel add-ins (.xlam) can also contain VBA, but .xlsm is the familiar format for a macro-enabled workbook.
Before running a macro, save a separate copy of the workbook. VBA changes are not reversed by Excel’s Undo command: macros cannot be undone with Ctrl+Z. A routine that clears a range or replaces values may leave no simple way to restore the original contents. Saving a backup first is especially important when the code was downloaded, received from someone else, or has not been reviewed.
On Windows, macro controls are under File > Options > Trust Center > Trust Center Settings > Macro Settings. The safest choice depends on your organization and the source of the file; avoid enabling all macros globally just to run one workbook. Use trusted files from known sources and follow prompts carefully. The editor shortcut is not a security bypass, and opening code for inspection does not establish that it is safe.
Frequently Asked Questions
What is the shortcut key for VBA in Excel?
In desktop Excel for Windows, press Alt+F11 to open the Visual Basic Editor. On a Mac, use Option+F11, adding Fn if the keyboard requires it.
Is Alt+F8 the VBA editor shortcut?
No. Alt+F8 opens Excel’s Macro dialog, which is used to select and run available macros. Alt+F11 opens the Visual Basic Editor.
Can I use VBA in Excel for the web?
No. Excel for the web does not run, create, or edit VBA macros. Open the workbook in desktop Excel to use the VBA editor and run its macros.
Why is my macro missing from the Alt+F8 list?
It may be in another workbook or outside the selected scope, or it may be a private, parameterized, or event procedure rather than a standard runnable macro. Check the project and procedure type in the VBE.
Can Ctrl+Z undo a VBA macro?
Usually not. Excel does not provide normal Undo history for changes made by a macro, so save a copy before running code that changes workbook data.
Related
- Excel Text to Columns: Split Cells at Line Breaks Easily
- Excel Text to Columns by Word: Methods That Work
- Excel Text to Columns: How to Keep Leading Zeros Safely
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA AutoFill: Methods, Examples, and FixesIn Excel VBA, use the Range.AutoFill method to extend a formula, value pattern, or formatting into a destination…
- Can You Have Macros in Google Sheets? How They WorkYes. Google Sheets supports macros: you can record a sequence of actions and replay it later, or edit…
- Excel VBA: How to Delete Column and Cell Ranges SafelyTo delete entire columns with Excel VBA, use a worksheet-qualified range such as ws.Columns("B:D").Delete. To delete only cells…
- VBA Can’t Find Project or Library? How to Fix ItThe VBA error “Can’t find project or library” usually means the workbook’s VBA project has a broken reference…
- VBA Loop Only Through Visible Rows?Yes. In Excel VBA, loop through the rows in your data range and check whether each row is…
- Simple Macro Recorder and Auto Clicker: How They WorkA simple macro recorder captures a sequence of actions—such as clicks, keystrokes, and pauses—and plays them back; an…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.