In Excel: Press Alt + F11 (Option + F11 on Mac) to open the Visual Basic Editor, then use Insert ▸ Module to create a place to write code. Excel for the web cannot create, run, or edit VBA macros. Open the workbook in the Excel desktop app to work with macros.
On this page8
VBA macro: Open the VBA Editor
Sub HelloFromTheEditor()
MsgBox "The VBA editor is working — this macro ran from the module you just created.", _
vbInformation, "VBA Editor"
End SubPaste this into the blank Module window and press F5. A dialog means the editor, the module and macro security are all set up correctly, so any later code you paste will run too.
How to run this macro
- Press Alt + F11 to open the VBA editor.
- Insert > Module.
- Paste the code above.
- Press
F5, or close the editor and run it from Developer > Macros. - Save the file as .xlsm so the macro is kept.
Press Alt + F11 from any worksheet (Option + F11 on Mac; on some laptops you also need the Fn key).
If the Project Explorer pane is missing on the left, press Ctrl + R to bring it back.
Expand the tree entry for your workbook, then expand Modules to read code that already exists.
To write new code, right-click the workbook name and choose Insert ▸ Module — the code window stays blank until a module is open.
Press Alt + F11 again to switch back to the sheet; the editor stays open in the background.
What this does
The Visual Basic Editor is a separate application window that ships inside Excel — it is where every macro in a workbook actually lives. Alt + F11 opens it from any sheet, with no setup and no Developer tab required. The editor is split into three panes. On the left, the Project Explorer lists every open workbook and add-in as a tree: sheet objects, ThisWorkbook, and any Modules the file contains. Below it, the Properties window shows the attributes of whatever is selected. The large area on the right is the code window, which stays blank until you open a module — a common reason people think the editor is broken on first launch. Existing macros are inside those Modules, so to read code someone else wrote, expand Modules in the tree and double-click one. Press Ctrl + G to add the Immediate window, where Debug.Print output lands. Before the code does anything, check the environment it needs: desktop Excel, a macro-enabled workbook (.xlsm) and macros allowed for this file. If the workbook came by email or download, Office can block its macros until the file is trusted. For “open vba in excel”, the reliable version is a short checking loop, not just the first command that appears to work. Run it on a deliberately small range first, watch how the affected cells change, and only then apply the same setup to the full sheet. When this is a ribbon command, the selection matters more than the button: confirm the range, apply the command, then spot-check the output before saving. That is what makes a workflow that saves repeating the same clicks every week useful in real work: repeatable, auditable, and not dependent on memory or luck.
A worked example
You inherit a workbook and want to see what it does before trusting it. Press Alt + F11. In the Project Explorer on the left, find the entry matching the file name, click the plus beside it, and expand the Modules folder. Double-click Module1 and its code appears on the right. If there is no Modules folder, the automation lives in a sheet object or in ThisWorkbook instead — double-click those to check. To write something of your own rather than read, right-click the workbook name, choose Insert ▸ Module, paste Sub HelloFromTheEditor() into the empty window, and press F5. Alt + F11 toggles back to the spreadsheet, and both windows stay open side by side. Every other macro task starts here, so knowing the editor layout turns a wall of unfamiliar panes into two clicks. It is also the fastest way to audit an unfamiliar workbook before you enable its macros: read the code first, decide second. Run a new macro on a copy of the workbook first. Do not count on Undo to reverse what a macro changed; the saved copy is your way back.
In Google Sheets
Google Sheets does not run VBA. A macro written for Excel has to be rewritten in Google Apps Script (Extensions ▸ Apps Script), and an .xlsm file converted to Sheets keeps its cells but drops the code. Nothing on this page is behind a login or a download: the exact answer is at the top, and the detail below it is there for when you need it. That is the whole promise here — the answer first, and just enough context to make it stick. For “open vba in excel”, the checks are about the environment as much as the code: desktop Excel with macros enabled for this file, a macro-enabled workbook and a saved copy to fall back on. Run it once on test data, compare the result with what the code says it does, and only then run it on the real sheet.
Common mistakes
- Expecting the Developer tab to be there first. It is not needed — Alt + F11 works whether or not the tab is visible. If you do want it, turn it on under File ▸ Options ▸ Customize Ribbon by ticking Developer.
- Typing into the grey background of the editor. That area is not a code surface; nothing accepts input until a Module (or a sheet object) is open in a code window.
- Writing a macro inside a sheet object such as Sheet1 when a standard module was meant. Code in a sheet object is scoped to that sheet and will not appear in the Developer ▸ Macros list, which makes it look like the macro vanished.
- Assuming a workbook has no code because Modules is empty. Event handlers live in ThisWorkbook and in the individual sheet objects, so check those before concluding the file is macro-free.
Frequently asked questions
Does Alt + F11 work on a Mac?
Option + F11 opens the editor on Mac, and on keyboards where the function keys default to media controls you need Fn + Option + F11. Tools ▸ Macro ▸ Visual Basic Editor from the menu bar always works as a fallback.
The editor opened but the window is completely blank — is it broken?
No. The code pane is empty until a module is open. Press Ctrl + R for the Project Explorer, then either double-click an existing module or use Insert ▸ Module to create one.
How do I see the VBA code someone else wrote in a workbook?
Alt + F11, expand the workbook in the Project Explorer, then expand Modules and double-click each one. Also check ThisWorkbook and the sheet entries — event code lives there rather than in a module.
Why is the project locked and asking for a password?
The author protected it under Tools ▸ VBAProject Properties ▸ Protection. Without that password the code cannot be viewed, and there is no supported way around it — ask whoever built the file.
Other ways people ask this
This is also commonly searched as “open vba in excel” and “how to open vba in excel mac”. They describe the identical operation, so you are in the right place no matter how you phrased it.
Why do people search for this in so many different ways?
Because the same task has many names. “open vba in excel”, “how to open vba in excel mac” all point at the one operation explained on this page, which is why they all lead here.