In Excel for Windows, press Alt+F11 to open the Visual Basic Editor (VBE), where you can view and edit VBA code. To see and run available macros instead, press Alt+F8; opening the editor does not run a macro.
The Excel VBA Shortcut on Windows
Alt+F11 is the standard keyboard shortcut for switching from an Excel workbook to the Visual Basic Editor and back. The VBE is the separate window used to write, inspect, and debug Visual Basic for Applications (VBA) code. Pressing the shortcut is a quick way to reach it without first displaying the Developer tab.
On some laptop keyboards, the function-key row also controls brightness, volume, or other hardware settings. If Alt+F11 does not open the editor, try holding the laptop’s Fn key as well, or check whether the keyboard has an Fn Lock setting. The precise behavior depends on the computer’s keyboard configuration.
You can also open the editor from the ribbon: choose Developer > Visual Basic. This command and Alt+F11 lead to the same environment. In the editor, the Project Explorer lists open workbooks and their sheets, while code windows display the VBA modules you select.
What Alt+F11 Does—and What It Does Not Do
Alt+F11 opens the editor; it does not automatically create a macro, execute code, or show the list of macros. That distinction matters because people often use “VBA shortcut” to mean several different things. Use the shortcut that matches the task:
- Alt+F11: open or return to the Visual Basic Editor.
- Alt+F8: open the Macro dialog, where you can select and run an available macro or open its options.
- Developer > Macros: open the same general macro-management dialog from the ribbon.
- Developer > Visual Basic: open the editor without using a keyboard shortcut.
A macro is a set of instructions, often saved in a workbook or in Excel’s Personal Macro Workbook. A VBA procedure is code within that project. The editor is where you work on code; the Macro dialog is a convenient place to start a listed procedure. Some procedures do not appear in the dialog—for example, a procedure that requires arguments or is declared as private—so their absence does not necessarily mean the code is missing.
How to Open the Editor and Find a Workbook’s Code
To inspect code associated with an open workbook, use this sequence on Windows:
- Open the workbook in the desktop version of Excel.
- Press Alt+F11.
- If the Project Explorer is not visible in the editor, press Ctrl+R to show it.
- Find the relevant workbook project, expand its folders, and double-click a sheet, ThisWorkbook, or a standard module to view its code.
Sheet-specific event procedures are stored with the corresponding worksheet object. Workbook events, such as an action that runs when the workbook opens, belong in ThisWorkbook. Ordinary reusable procedures are commonly placed in a standard module. If the Project Explorer shows several open projects, check the workbook name before editing anything; code in the Personal Macro Workbook is not the same as code stored in the workbook you are viewing.
If an editor window seems to have disappeared, look for it behind the Excel window or check the open project and code windows in the VBE. Alt+F11 may move focus between Excel and the editor rather than create a new editor window every time.
Assigning a Shortcut to a Macro
Alt+F11 is Excel’s shortcut for the editor, not a key combination that you can replace with a macro of your own. If your goal is to trigger a particular macro quickly, assign that macro a shortcut instead. In Excel for Windows, press Alt+F8, select the macro, choose Options, and enter a letter in the shortcut-key box. Excel uses Ctrl plus that letter; holding Shift as well creates a Ctrl+Shift combination.
Choose a combination carefully. A Ctrl-plus-letter shortcut can override a built-in Excel shortcut while the macro is available, so Ctrl+Shift plus a letter is often less likely to conflict with a familiar command. The shortcut is associated with the macro’s location and availability: a macro stored only in a particular workbook may not be available after that workbook is closed. For a shortcut intended for use across workbooks, the Personal Macro Workbook is one possible storage location, but it must be available when Excel starts.
To remove or change an assigned key, return to the Macro dialog’s options for that macro and edit the shortcut. Before assigning one, confirm the selected macro name and workbook in the dialog; a similarly named procedure in another open workbook may not be the one you intend to run.
Running a Macro from the Editor
You can run a suitable procedure from the VBE by placing the insertion point inside it and choosing Run > Run Sub/UserForm, or by pressing F5. For many ordinary macros, Alt+F8 is simpler because it presents a selectable list. The following example formats cells A1 through D1 on the active worksheet:
Before running any macro, save a copy of the workbook. Macro actions cannot be undone with Ctrl+Z, so check that the active sheet is the intended one.
Sub FormatHeader()
' Format the first four cells on the active sheet.
Dim ws As Worksheet
Set ws = ActiveSheet
With ws.Range("A1:D1")
.Font.Bold = True
.Interior.Color = RGB(217, 225, 242)
End With
End Sub
In the VBE, choose Insert > Module if the project needs a standard module, then place the procedure in that module. Return to Excel, press Alt+F8, select FormatHeader, and choose Run. The macro changes formatting only; it does not enter or alter cell values. It acts on whichever worksheet is active when it runs, so select the intended sheet first.
Showing the Developer Tab
The Developer tab is useful if you prefer ribbon commands to keyboard shortcuts. On Windows, enable it through File > Options > Customize Ribbon, then check Developer in the list of main tabs and confirm. The tab then provides commands such as Visual Basic, Macros, and controls for working with forms.
You do not need to enable the Developer tab to use Alt+F11 or Alt+F8. If the tab is missing, that alone does not mean VBA is unavailable. Conversely, seeing the tab does not mean macros are automatically trusted or enabled; Excel’s security settings still apply.
Saving and Macro Safety
A workbook containing VBA generally needs a macro-enabled format. Use Excel Macro-Enabled Workbook (*.xlsm) when saving a workbook with macros. Saving it as a standard .xlsx file does not preserve VBA project code; Excel may warn that the features cannot be saved in that format. If the code is intended as an add-in or stored in a different kind of project, the appropriate file format can differ, but .xlsm is the usual choice for a macro-enabled workbook.
Macro security is a separate issue from the shortcut. Excel may block code from an untrusted file or show a security warning. Only enable macros when you trust the file’s source and understand why the code is needed. A macro can change or delete workbook data, access files, and perform other actions permitted to it, so treat unfamiliar code as executable software rather than harmless text.
- Keep an unchanged backup before editing or running unfamiliar code.
- Review the workbook’s source and macro purpose before enabling its content.
- Do not lower global macro security just to make one unknown file run.
- Remember that Ctrl+Z does not reverse changes made by VBA.
Mac and Excel for the Web
In desktop Excel for Mac, the equivalent editor shortcut is generally Option+F11; the macro dialog shortcut is generally Option+F8. Mac keyboards and system settings can reserve function keys for hardware controls, so you may need to include Fn, or adjust the keyboard’s function-key behavior. The Developer tab and ribbon commands are alternatives if the key combination behaves differently on a particular Mac.
Excel for the web does not create, edit, or run VBA macros. A workbook with VBA can be opened there, but use desktop Excel to work with its VBA project or run its macros. This limitation is specific to VBA: Excel for the web has other automation options, but they are not the same as running a VBA procedure, and they may not be available in every account or environment.
Common Shortcut Problems
If Alt+F11 appears to do nothing, first confirm that you are using the desktop application rather than Excel in a browser. Then try Fn+Alt+F11 if your keyboard uses media functions on its F keys. You can also open Developer > Visual Basic to determine whether the issue is the shortcut or access to the editor itself.
If the editor opens but a workbook’s code is not visible, show the Project Explorer with Ctrl+R and expand the correct project. The code may be in a sheet object, ThisWorkbook, a standard module, or a different open workbook. If you cannot view a project, it may be protected; do not assume that the editor shortcut failed.
If Alt+F8 opens a dialog with no relevant macro, check that the file containing the macro is open, that the correct workbook is selected in the dialog, and that the procedure is eligible to appear in the list. If Excel blocks the macro, resolve the security issue only after verifying that the file is trusted. The editor shortcut itself does not bypass macro security.
Frequently Asked Questions
What is the shortcut to open VBA in Excel?
In Excel for Windows, press Alt+F11. On desktop Excel for Mac, use Option+F11, sometimes with Fn depending on the keyboard settings.
What shortcut runs a macro in Excel?
Press Alt+F8 on Windows to open the Macro dialog, choose a listed macro, and select Run. You can also assign an eligible macro a shortcut through the dialog’s Options button.
Does Alt+F11 run a macro?
No. It opens or switches to the Visual Basic Editor. Use Alt+F8, a macro’s assigned shortcut, or the VBE’s Run command to execute code.
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 for those tasks.
Why does Alt+F11 not work on my laptop?
The keyboard may require Fn to access F11, or you may be using Excel for the web. Try Fn+Alt+F11 on Windows, or use Developer > Visual Basic in desktop Excel.
Related
- Excel Absolute References on Windows: How to Use Them
- Excel Name Box: Change a Range or Named Range
- How to See Named Ranges in Excel and Check Their Cells
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Range Column: How to Reference ColumnsIn VBA, reference a whole worksheet column with Columns("C") or Range("C:C"); to get the column containing a particular…
- VBA Loop Example: For, Do While, and For Each LoopsA VBA loop repeats a block of code, either a set number of times or until a condition…
- Excel UserForm Keeps Changing Size? Causes and FixesAn Excel UserForm usually changes size because VBA or its AutoSize setting changes its dimensions, or because Windows…
- Excel VBA: Create an Outlook Email Draft in WindowsYes. In Excel for Microsoft 365 on Windows, VBA can use classic Outlook’s object model to create an…
- How to List All Files in a Folder Using Excel VBATo list files directly inside a folder in Excel for Microsoft 365 on Windows, run a VBA macro…
- VBA Array Size: Practical Limits, Bounds, and Memory UseThere is no single fixed maximum size for a VBA array: its practical limit depends on available memory,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.