The VBA editor (officially the Visual Basic for Applications editor, or VBE) in Excel is a separate window that opens from the Developer tab: go to Developer > Visual Basic, or press Alt+F11 on Windows. On a Mac, press Option+F11 or use Tools > Macro > Visual Basic Editor. If the Developer tab is missing, you can still reach the editor with the keyboard shortcut, or enable the tab via Excel Options > Customize Ribbon.
Menu labels and tab names can differ slightly by Excel version, platform and region, so if a name below is not exactly what you see, look for the closest matching item.
What You'll Need
- Excel installed on Windows or macOS (the editor is a desktop feature; Excel for the web does not include a VBA editor).
- A workbook that is saved in a macro-enabled format (.xlsm or .xlsb) if you intend to keep any code you write. Standard .xlsx files discard macros when saved.
- Macro security awareness: macros can run code on your computer, so only enable them in files you trust.
Step-by-Step
- Open the workbook you want to work with. You can open the VBA editor from any workbook, even a blank one, but the code you write lives inside that specific file.
- Try the keyboard shortcut first. On Windows, press Alt+F11. On a Mac, press Option+F11. This opens the editor regardless of whether the Developer tab is visible, and it is the fastest route.
- Or use the Developer tab. Click Developer on the ribbon, then click Visual Basic in the Code group. If you do not see a Developer tab, skip to the next step.
- Enable the Developer tab if it is hidden. On Windows, click File > Options > Customize Ribbon, tick the Developer checkbox in the right-hand list, and click OK. On a Mac, open Excel > Preferences > Ribbon & Toolbar, tick Developer, and close the dialog.
- Alternatively, reach it through the Macro dialog. Click View > Macros > View Macros (or press Alt+F8 on Windows), then type a new name in the Macro name box and click Create. Excel creates an empty subroutine and opens the VBA editor at that point.
- Find the Project Explorer. In the editor window, the Project Explorer pane on the left lists every open workbook. If it is hidden, use View > Project Explorer inside the editor, or press Ctrl+R.
- Insert a module. Right-click your workbook's name in the Project Explorer, choose Insert > Module. A blank code window appears. Standard modules are where general-purpose macros belong; sheet modules are for code tied to a specific worksheet's events.
- Write or paste your code. Type a simple test such as
Sub Hello()on one line,MsgBox "Hello"on the next, andEnd Subon the last. Press F5 to run it, or use Run > Run Sub/UserForm. - Close the editor when you are done. Click the X on the VBA editor window or press Alt+Q (Windows) or Cmd+Q (Mac) to return to Excel. Your code stays attached to the workbook.
- Save in a macro-enabled format. Use File > Save As and choose Excel Macro-Enabled Workbook (.xlsm). If you save as .xlsx, Excel warns that macro-free format will remove the code.
Common Mistakes
- Looking for the Developer tab in Excel for the web. The browser version has no VBA editor at all. Open the file in desktop Excel to write or edit macros.
- Typing code into a sheet module by accident. Code in a worksheet module only responds to events on that sheet. General macros should go in a standard module.
- Forgetting that macros are stored per workbook. A macro typed into one file will not appear in another. If a shortcut seems broken, check which workbook is active.
- Saving as .xlsx and losing the code. Always confirm the format before closing a workbook that contains macros.
- Using Alt+F11 in another Office app. The same shortcut opens that app's own VBA editor, which is a different project. Confirm you are in Excel.
- Assuming a shortcut failure means the feature is gone. Some keyboards, especially laptop keyboards, require Fn together with the function keys. Try Fn+Alt+F11.
Tips
- The editor remembers its last position, so if it opens off-screen, use Window > Cascade inside the editor to bring it back into view.
- Use Debug > Compile VBAProject before running anything substantial; it catches syntax errors early.
- Immediate Window (press Ctrl+G in the editor on Windows) lets you test single lines of code without writing a full procedure.
- Keep the Object Browser handy (F2 in the editor) to look up built-in objects and methods instead of guessing names.
- Name your modules descriptively in the Properties window so a workbook with several modules stays readable.
- Back up macro-enabled workbooks before major edits; the editor has no undo history across sessions.
Troubleshooting
The Alt+F11 shortcut does nothing. Click inside the Excel window first so it has focus, then try again. On laptops, add Fn. If a third-party utility has reassigned the key, use Developer > Visual Basic instead.
Developer tab will not stay visible. Reopen File > Options > Customize Ribbon and check that Developer is ticked for the correct ribbon customisation set. Some organisations lock the ribbon with group policy, in which case ask your IT administrator.
The editor opens but the code is greyed out. The project may be locked for viewing. In the editor, use Tools > VBAProject Properties and check the Protection tab. If a password you do not know is set, you cannot edit that project.
You get a security warning when opening a file with macros. Excel disables macros by default for files from other sources. Only click Enable Content when you trust the file and its origin. If macros you wrote yourself are being blocked, check File > Options > Trust Center > Trust Center Settings and review the macro settings.
The editor is unresponsive or crashes. Save your workbook, close Excel completely, and reopen it. If the problem persists, start Excel with add-ins disabled to identify a conflicting add-in, then re-enable them one at a time.
Frequently Asked Questions
Can I open the VBA editor in Excel on a phone or tablet?
No. The Excel mobile apps do not include a VBA editor. You need the desktop version for Windows or macOS.
Is the VBA editor available in Excel for the web?
No. The browser version does not provide a VBA editor or a way to author macros. You can open the file on the desktop to work with code.
Why can I not see the Developer tab?
It is hidden by default. Enable it in Excel Options > Customize Ribbon on Windows, or Excel > Preferences > Ribbon & Toolbar on a Mac. The keyboard shortcut works even when the tab is hidden.
Does opening the VBA editor change my spreadsheet?
No. Opening the editor alone does not change cell contents or formatting. Changes only happen when you write code, run a macro, or save the workbook in a different format.
Where do my macros go after I close the editor?
They remain stored in the workbook they were created in, provided you save it as an .xlsm or .xlsb file. Reopen the editor to see them under that workbook's project.
Can I use the VBA editor on a Mac?
Yes, desktop Excel for macOS includes a VBA editor, reached with Option+F11 or Tools > Macro > Visual Basic Editor. Some Windows-only features are unavailable, so code may need adjusting between platforms.