In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic for Applications (VBA) Editor. You can also open it from the Developer tab by selecting Visual Basic. On a Mac, use Tools > Macro > Visual Basic Editor or the Developer tab. You need the desktop version of Excel; Excel for the web cannot open or edit the VBA Editor. The steps below explain how to open the editor, find a workbook’s code, and fix common access problems.
What You’ll Need
- Excel for Windows or Mac: VBA editing is available in the desktop Excel app. It is not available in Excel for the web or the Excel mobile apps.
- A workbook, if you want to view its code: Open the workbook in Excel before opening the editor. You can open the editor without a workbook, but there will be no workbook project to inspect.
- A keyboard shortcut or access to the ribbon: The shortcut is quickest, but the Developer tab provides a visible route if you prefer menus or your keyboard shortcut is intercepted.
You do not need to enable macros just to open the editor or look at code. Macro security controls whether code can run; it is separate from opening the VBA window. If you plan to change or create macros, save your work in an appropriate macro-enabled format, such as Excel Macro-Enabled Workbook (.xlsm), so the VBA project can be retained.
Step-by-Step
- Open the workbook in desktop Excel. Start Excel and open the file whose VBA project you want to view. If the file is in a browser, choose the option to open it in the desktop app. Excel for the web can display workbook content, but it does not provide the VBA Editor. If you only want to explore the editor, you can also open a blank workbook first.
- Try the Windows keyboard shortcut. With Excel active, press Alt+F11. In most desktop setups, the Visual Basic Editor opens in a separate window. On some laptops, the function keys control brightness or other hardware features; if nothing happens, try Fn+Alt+F11, or use the Developer tab instead. Make sure Excel—not another application—is the active window when you press the keys.
- Open it from the Developer tab if needed. In Excel, select Developer > Visual Basic. The Developer tab is normally in the ribbon, often toward the right. Selecting Visual Basic opens the same editor as the keyboard shortcut. If you do not see Developer, continue to the next step to turn on the tab; enabling it only changes the ribbon display and does not enable or run macros.
- Show the Developer tab in Excel for Windows. Select File > Options > Customize Ribbon. Under Main Tabs in the right-hand list, select the checkbox beside Developer, then select OK. Return to the workbook and select Developer > Visual Basic. If the Developer box was already checked, close Options and look across the ribbon for the tab; a narrow window may hide or compress ribbon items.
- Open the editor on a Mac. In desktop Excel for Mac, select Tools > Macro > Visual Basic Editor. You can also use Developer > Visual Basic if the Developer tab is displayed. On many Mac keyboards, Option+F11 opens the editor; depending on the keyboard and macOS function-key settings, you may need to press Fn+Option+F11. If the tab is missing, open Excel’s Settings or Preferences, choose Ribbon & Toolbar, and enable Developer under the main tabs. Labels can vary slightly between Mac releases.
- Find the workbook in Project Explorer. When the editor opens, look for the Project Explorer pane, usually on the left. It lists open VBA projects with names such as VBAProject (Budget.xlsm). Select the project for the workbook you opened. If the pane is absent, choose View > Project Explorer in the editor; on Windows, Ctrl+R is also a shortcut for showing it. If you have several workbooks open, check the project name before opening a code item.
- Open the code you need to inspect. Expand the project by selecting its plus sign or disclosure arrow. Expand Microsoft Excel Objects to see worksheet objects and ThisWorkbook. Double-click one of these items to view code attached to that sheet or workbook. Expand Modules and double-click a module, such as Module1, to view a standard macro module. If Modules is not listed, the project may not contain a standard module; that does not necessarily mean the workbook has no VBA, since code can be attached to a worksheet or ThisWorkbook.
To return to the workbook, switch to the Excel window or close the editor window. Closing the editor does not close the workbook. If you make changes to code, save the workbook from Excel and keep it in a macro-enabled format if you need to preserve the VBA project. For a file that already contains macros, avoid saving it as .xlsx: that format does not store VBA code and Excel may warn that the project will be removed.
Common Mistakes
- Looking for the editor in Excel for the web. The browser version does not include the VBA Editor. Opening a workbook in a desktop app is required to view or edit VBA code.
- Assuming the Developer tab is on by default. It may be hidden until you enable it in ribbon settings. The absence of the tab does not mean your Excel installation lacks VBA.
- Confusing opening the editor with running a macro. The Visual Basic Editor is a place to inspect or edit code. Opening it does not run a macro and does not require changing macro security settings.
- Double-clicking the wrong item in Project Explorer. Worksheet and workbook objects contain event code, while standard procedures are usually in modules. Check the project name and expand the relevant folder before opening an item.
- Saving a macro workbook as .xlsx. This can remove its VBA project. Use .xlsm for a regular macro-enabled workbook, or the appropriate macro-enabled format for another workbook type.
- Expecting Ctrl+Z to undo code changes. The Excel undo history does not reliably undo VBA edits, and running a macro cannot be reversed with Ctrl+Z. Keep a separate copy before editing unfamiliar code or running a macro.
Tips
- Use the shortcut for frequent access. On Windows, Alt+F11 is usually the fastest route. On Mac, use the Tools menu or Developer tab if the function-key combination conflicts with your keyboard settings.
- Keep the Excel and editor windows distinct. The editor is a separate application window, so it may open behind Excel or on another monitor. Use the taskbar, Dock, or window switcher if it seems to have disappeared.
- Check which project you are editing. If multiple workbooks are open, Project Explorer can show several VBAProject entries. A code window’s title and the project tree help confirm which file the code belongs to.
- Make a backup before changing code. Save a copy of the workbook before editing or running unfamiliar VBA. Macros can alter cells, files, or other workbook content, and their actions cannot generally be undone with Excel’s normal undo command.
- Preserve the file type. For a workbook containing VBA, use .xlsm when saving a standard Excel workbook. If you are only viewing code, you do not have to change the file format.
- Use the menu when shortcuts are unreliable. Keyboard layouts, laptop function-key modes, remote desktop software, and other applications can intercept key combinations. The ribbon or Mac menu offers a dependable alternative.
Troubleshooting
Alt+F11 does nothing on Windows: Click inside the Excel window first, then try again. If your keyboard uses the function row for media or system controls, try Fn+Alt+F11. If that still fails, enable the Developer tab using File > Options > Customize Ribbon, then select Developer > Visual Basic. If neither route works, check whether your organization has restricted VBA or whether you are using a limited Excel environment.
The Developer tab is missing: On Windows, open File > Options > Customize Ribbon, select the checkbox for Developer under Main Tabs, and choose OK. On Mac, open Excel’s Settings or Preferences and look under Ribbon & Toolbar. If the setting is unavailable or changes are blocked, an administrator may control Office settings.
The editor opened, but the project list is missing: In the editor, choose View > Project Explorer. If the pane appears but has no project for the file you expect, return to Excel and confirm that the workbook is open in the desktop app. You can also look for a collapsed pane or a project listed under a different workbook name.
You cannot see the code for a project: Expand the project and inspect both Microsoft Excel Objects and Modules. Some code belongs to a worksheet or ThisWorkbook rather than a standard module. A project may also be password-protected for viewing; do not try to bypass that protection. Ask the workbook owner or administrator for authorized access.
Excel says macros are blocked or disabled: That warning concerns running code, not necessarily opening the editor. Do not lower security settings just to view VBA. If you need to run a macro, confirm that the workbook and its source are trusted, then follow your organization’s security rules. Files downloaded from the internet may be subject to additional Microsoft Office security controls.
You are using Excel in a browser: Choose the command to open the file in the desktop Excel app, if available, and then use the Windows or Mac steps above. If you do not have desktop Excel access, you will need an authorized desktop installation to view or edit VBA; the browser editor cannot provide that feature.
Frequently Asked Questions
Does opening the VBA Editor enable macros?
No. Opening the editor lets you view or edit VBA code. Whether macros are allowed to run is controlled separately by Excel’s security settings and, in some cases, your organization.
Can I open the VBA Editor in Excel for the web?
No. Excel for the web does not provide the VBA Editor or support creating, editing, or running VBA macros. Open the workbook in desktop Excel to work with its VBA project.
What is the shortcut to open the VBA Editor?
In Excel for Windows, press Alt+F11. On Mac, Option+F11 may work, sometimes with Fn as well; the Tools menu or Developer tab is an alternative.
Why is there no Modules folder in Project Explorer?
The workbook may not have a standard module. Expand Microsoft Excel Objects to check for worksheet or ThisWorkbook code. If no code items are present, the project may simply contain no VBA, or access may be restricted.
Do I need to save as .xlsm just to view VBA?
No. You can open and inspect code without changing the file type. If you create or edit VBA and want to keep it, save a copy in a macro-enabled format such as .xlsm rather than .xlsx.
Can I undo a change made in the VBA Editor?
Do not rely on Excel’s Ctrl+Z history for VBA edits, and a macro’s effects cannot generally be undone with Ctrl+Z. Save a backup before making changes or running code, then restore that copy if needed.
Related
- How to Open an IQY File in Excel and Load Web Data
- How to Unhide Rows in Excel: Quick Steps and Fixes
- How to Open an IIF File in Excel Without Losing Data
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA PasteSpecial: Values, Formats, and MoreIn Excel VBA, use Range.PasteSpecial after copying a source range to paste only selected parts, such as values,…
- VBA Copy and Paste a Sheet: Code and OptionsTo copy a worksheet with VBA, use the sheet’s Copy method and specify where the duplicate should go.…
- Outlook Macros: How to Enable Them Safely in Classic OutlookTo enable VBA macros in classic Outlook for Windows, open File > Options > Trust Center > Trust…
- Excel VBA Reset Error Handling: What Err.Clear DoesTo turn off an active VBA error handler in the current procedure, use On Error GoTo 0. Use…
- Excel VBA Uppercase: UCase, Macros, and Cell OptionsYes. In Excel VBA, use UCase$ to return a text string in uppercase; to change worksheet cells, assign…
- Excel VBA Optional Parameters: Syntax and ExamplesYes. In Excel VBA, declare an optional parameter with the Optional keyword, usually followed by a default value,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.