In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, where you can view and edit VBA macros. You can also open it from Developer > Visual Basic. If the Developer tab is not visible, enable it first in Excel Options. These instructions are for the desktop app; Excel for the web does not include the VBA editor.
What You’ll Need
- Excel desktop for Windows or Mac. The Visual Basic Editor is not available in Excel for the web.
- A workbook, if you want to inspect its macros. A macro-enabled workbook usually has an
.xlsmextension. VBA can also be stored in an Excel binary workbook (.xlsb), an add-in, or your Personal Macro Workbook. - Permission to access the file. A workbook may be read-only, protected, or have its VBA project locked with a password. You can open the editor without a workbook, but you will need the correct project and permissions to view or change its code.
Step-by-Step
- Open the Excel desktop app. Start Excel on your Windows PC and open the workbook whose macros you want to inspect. If you are starting with a blank workbook, that is fine too. Opening the editor does not run a macro; it simply opens the separate Visual Basic Editor window. If the file came from another person or the internet, follow your organization’s security guidance before enabling its content.
- Try the Windows keyboard shortcut. Press Alt+F11. On most Windows keyboards, press and hold Alt, tap F11, then release the keys. The Visual Basic Editor should open in a separate window. If nothing happens, see whether your keyboard requires the Fn key for function-row keys, or use the Developer tab method below.
- Open the editor from the ribbon. In Excel, select Developer > Visual Basic. The Visual Basic Editor opens separately from the worksheet window. If you do not see Developer, continue to the next step to show the tab. The ribbon command and keyboard shortcut open the same editor, so you can use whichever is more convenient.
- Show the Developer tab if it is missing. In Windows Excel, select File > Options > Customize Ribbon. In the list under Main Tabs, select the checkbox next to Developer, then choose OK. Return to the workbook and look for Developer on the ribbon. This changes which ribbon tab is displayed; it does not enable macros or change the workbook’s security settings.
- Find the correct workbook project. In the editor, look for the Project Explorer pane, which lists open workbooks and other VBA projects. If it is not visible, press Ctrl+R or select View > Project Explorer. Expand the project for your workbook, commonly shown as
VBAProject (WorkbookName.xlsm). If the pane is still not easy to spot, check whether it is behind another window or docked at the side of the editor. - Open a code module or workbook object. Expand the project’s folders. Double-click Modules and then a module, such as Module1, to view ordinary macro code. To inspect code attached to a worksheet or the workbook itself, expand Microsoft Excel Objects and double-click the relevant sheet or ThisWorkbook. Those object windows can contain event procedures, which run in response to actions such as opening a workbook or changing a cell.
- Return to Excel when you are done. You can switch between the editor and workbook using the Windows taskbar or the open windows. Close the Visual Basic Editor window when finished, or use Alt+Q to return to Excel. If you made changes to code, save the workbook in a macro-capable format such as
.xlsm; saving a workbook containing VBA as.xlsxremoves the VBA project.
Common Mistakes
- Using Alt+F8 instead of Alt+F11. Alt+F8 opens Excel’s Macro dialog, which lists available macros you may be able to run. It is not the code editor. Use Alt+F11 or Developer > Visual Basic to open the editor.
- Looking for VBA in the worksheet ribbon. The editor is a separate window, not a worksheet pane. It may open behind Excel or on another monitor, especially if you previously used a multi-monitor setup. Check the taskbar and move or restore the window if needed.
- Assuming the Developer tab is required for the shortcut. The tab can be hidden while Alt+F11 still works. Enabling Developer is useful for finding the Visual Basic command and other developer tools, but it is not a prerequisite for the shortcut.
- Confusing opening the editor with enabling macros. Opening the editor does not run code or automatically make a downloaded workbook safe. Macro warnings and organizational policies are separate from access to the editor. Do not enable content just to look at a workbook unless you trust its source and understand the risk.
- Saving VBA in the wrong file type. The standard
.xlsxformat does not preserve VBA code. If you edit a macro and save as.xlsx, Excel warns that the VBA project cannot be saved in that format. Choose a macro-enabled format such as.xlsmif you need to keep the code.
Tips
- Know where macros can be stored. A macro may not be in the workbook you currently have open. Check the Project Explorer for other open workbooks, add-ins, or
PERSONAL.XLSB, which Excel may load in the background for macros available across workbooks. - Use the Macro dialog to identify a macro, not edit it. Alt+F8 can help you see macros available to run and, in some cases, select one to locate its code. If the code is in a sheet, ThisWorkbook, an add-in, or a locked project, the Macro dialog may not take you directly to an editable module.
- Keep a backup before changing code. Save a separate copy of the workbook before editing or running an unfamiliar macro. VBA changes to cells cannot be reversed with Ctrl+Z, and code can make broad changes to workbook data.
- Make the editor easier to navigate. If you are new to VBA, keep Project Explorer visible and use the Properties window when you need to inspect a selected sheet or workbook object. The Properties window can be shown through View > Properties Window.
- Use the Mac equivalent where appropriate. In Excel for Mac, the common shortcut is Option+F11; on some keyboards you may need to hold Fn as well. You can also use Developer > Visual Basic. If Developer is hidden, open Excel > Settings (or Excel > Preferences in some releases), choose Ribbon & Toolbar, and enable Developer under the main tabs. Menu labels can vary slightly by Mac release.
Troubleshooting
Alt+F11 does nothing: Use Developer > Visual Basic if the tab is available. On a laptop, the function keys may control brightness or media, so try Fn+Alt+F11. Alternatively, enable Developer using File > Options > Customize Ribbon and open the editor from the ribbon. If you use remote desktop or other keyboard software, it may intercept the shortcut.
The Developer tab is still missing: Confirm that you selected the Developer checkbox under File > Options > Customize Ribbon > Main Tabs, then choose OK. If the setting is controlled by your employer or school, an administrator may restrict ribbon customization. Excel for the web has different capabilities and does not provide the desktop VBA editor, so open the workbook in the desktop app instead.
The editor opens, but you cannot find your code: In Project Explorer, expand each relevant project and check both Modules and Microsoft Excel Objects. Also check whether the macro belongs to another open workbook or PERSONAL.XLSB. A macro may be stored in an add-in rather than the file you first expected. If the project is locked, Excel may ask for a password before showing its contents; you need authorization and the correct password to inspect it.
You can see code but cannot save it: Check whether the workbook is read-only, stored in a location where you lack write permission, or protected by your organization. If Excel displays a warning about unsupported features, do not save a VBA-enabled workbook as .xlsx if you need to keep its macros. Use .xlsm or another suitable macro-capable format, and save a backup before making edits.
You are using Excel for the web: The browser version can preserve some macro-enabled workbook files, but it cannot open or edit VBA code, and it cannot run VBA macros. Choose Open in Desktop App if available, or download the file and open it in desktop Excel. If you do not have desktop Excel, ask the file owner or your organization for an appropriate desktop environment rather than trying to edit VBA in the browser.
Frequently Asked Questions
What is the shortcut to open the macro editor in Excel?
On Windows, press Alt+F11. On Mac, use Option+F11; depending on the keyboard, you may also need Fn. These shortcuts open the Visual Basic Editor, not the Macro dialog.
Is the macro editor the same as the Macro dialog?
No. The Visual Basic Editor is where you inspect and edit VBA code. On Windows, Alt+F8 opens the Macro dialog, which is mainly for viewing and running available macros. Opening the editor does not run a macro.
Can I open the VBA editor in Excel for the web?
No. Excel for the web does not provide the Visual Basic Editor or run VBA macros. Open the workbook in Excel desktop for Windows or Mac to work with VBA.
Do I need to enable macros to open the editor?
Not necessarily. You can usually open the Visual Basic Editor without enabling a workbook’s macros. Macro security controls whether code can run; it is separate from opening the editor. Follow your organization’s security rules and do not enable code from an untrusted source.
Why is a workbook’s code missing from the editor?
The code may be stored in another open project, an add-in, PERSONAL.XLSB, a worksheet object, or ThisWorkbook rather than a standard module. The VBA project may also be password-locked. Expand the projects in Project Explorer and check the likely locations.
Will editing a macro affect my workbook?
It can. A macro may change cells, sheets, or files when run, and those changes generally cannot be reversed with Ctrl+Z. Save a separate workbook copy before running or changing code, and use a macro-enabled file format if you need to retain VBA.
Related
- How to Insert a Page-Wide Line Across a Word Document
- How to Insert a Neat Line in Word: Clean, Straight Results
- How to Insert a Name Line in Word
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Create a Toggle Button in Excel VBA: Setup and CodeTo create a toggle button in Excel VBA on Windows, choose Developer > Insert > Toggle Button under…
- Excel Macro Disabled? How to Enable Macros SafelyIf an Excel macro is disabled, first confirm the workbook is from a source you trust, then check…
- Access VBA Dictionary: Create and Use Scripting.DictionaryYes. In Access VBA, you can use the Scripting.Dictionary object to store pairs of keys and values, check…
- Excel VBA LAMBDA: Calling Worksheet Functions from VBAExcel’s LAMBDA function is a worksheet feature, not a VBA language feature: VBA has no built-in anonymous-lambda syntax.…
- VBA Range.Hidden: How to Check Hidden Rows and ColumnsIn Excel VBA, Range.Hidden checks or sets whether entire rows or columns are hidden; it does not hide…
- Excel VBA Resize: Change a Range’s Size with VBA CodeIn Excel VBA, use the Resize property to refer to a range with a different number of rows…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.