To open the VBA coding window in Excel, press Alt + F11 on a Windows PC, or go to Developer > Visual Basic on the ribbon. The Alt + F11 shortcut works on both Windows and Mac versions of Excel, and it opens the Visual Basic for Applications (VBA) Editor, the separate window where macros, modules and user forms live. If you have never used it, nothing is broken and nothing changes until you save — you can open the editor, look around and close it again without altering your workbook. Exact ribbon labels can differ slightly by Excel version, platform and region, which is why the keyboard shortcut is the reliable route.
What You'll Need
- Microsoft Excel for Windows or Mac (the desktop app, not Excel for the web). Excel for the web cannot run or edit VBA at all — you need the installed desktop application.
- A saved workbook. Macros can only be stored in files saved as .xlsm (macro-enabled), .xlsb, or the older .xls format. A standard .xlsx file discards any code you write.
- Permission to run macros on the machine. In many corporate environments, macro execution is blocked by group policy or by an admin — if so, the editor may open but code will not run, or the option may be greyed out entirely.
- No additional installation. The VBA editor ships with every desktop copy of Excel.
Step-by-Step
- Save your workbook first. Press Ctrl + S (Cmd + S on Mac). If you intend to write code, use File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm) from the file type dropdown. Skipping this is the single most common reason work disappears.
- Open the VBA Editor with the shortcut. Press Alt + F11. On a Mac, the function keys may be mapped to system controls, so you might need Fn + Alt + F11, or use the menu route in the next step. The editor opens as its own window titled Microsoft Visual Basic for Applications.
- Or use the ribbon. If you have not used the Developer tools before, they may be hidden. Right-click any empty area of the ribbon and choose Customize the Ribbon, then tick Developer in the list on the right and click OK. The Developer tab now appears; click Developer > Visual Basic to open the same editor. On a Mac you may instead find it under Tools > Macro > Visual Basic Editor.
- Familiarise yourself with the three panels. The top-left is the Project Explorer, listing every open workbook and its components — sheets, ThisWorkbook, and any modules. The bottom-left is the Properties window (press F4 if it is missing). The large grey area in the middle is where code windows appear.
- Insert a module. In the Project Explorer, right-click your workbook's name (not a sheet), choose Insert > Module. A blank white window opens. This is where general-purpose macros belong. If you instead paste code directly into a sheet's code module, it will only fire on events for that sheet, which confuses beginners.
- Type a one-line test. In the blank module, type
Sub Hello(), press Enter, typeMsgBox "It works", press Enter, then typeEnd Sub. Press F5 with the cursor inside the routine to run it; a small message box should appear. - Return to the spreadsheet. Press Alt + F11 again, or click the Excel icon at the top-left of the editor. The editor stays open in the background with your code intact.
- Run the macro from Excel itself. Press Alt + F8 to open the Macro dialog, select your macro name and click Run. Developer > Macros opens the same list. If you saved as .xlsm you will be prompted to enable content the next time you open the file.
Common Mistakes
- Writing code in a .xlsx file. Excel will warn you on save that macro-free formats cannot store VBA. If you click through, all your code is discarded. Always use Save As and pick the macro-enabled format before you start.
- Putting general code in a sheet module. Code in Sheet1 is tied to that sheet's events. Ordinary macros belong in a standard module you insert yourself.
- Confusing the Macro dialog with the editor. Alt + F8 lists macros to run; Alt + F11 opens the editor where you write them. Both are needed at different moments.
- Not enabling the Developer tab and assuming VBA is missing. The tab is hidden by default in recent versions; it is a ribbon setting, not a feature removal.
- Panicking at a grey editor with no panes. Pressing F4 restores Properties, Ctrl + R restores the Project Explorer. A completely empty grey window is normal until you insert a module.
- Leaving the macro recorder running or forgetting to stop it. The recorder captures every click, which produces bloated, slow code. Stop recording before doing unrelated formatting.
Tips
- The editor is a separate window with its own zoom and layout; it remembers where you left your panes between sessions.
- Use F8 to step through code one line at a time when debugging, and F9 to set or clear a breakpoint on a line.
- Indent consistently and comment with a leading apostrophe. VBA ignores anything after it on that line — useful for leaving notes for your future self.
- Naming a module something descriptive (for example
modReports) saves hunting later; the Project Explorer shows module names, not their contents. - Keep a backup copy of a working macro-enabled workbook before making big changes. There is no undo inside the VBA editor — Ctrl + Z works for typing, but deleting a whole module is not recoverable.
- The macro recorder is the fastest way to learn syntax: record a short action, open the editor, and read what Excel wrote. It is often verbose but always syntactically correct.
Troubleshooting
Alt + F11 does nothing. A function-key lock (Fn) may be active on laptops, or another add-in has captured the shortcut. Try Fn + Alt + F11, then use Developer > Visual Basic instead.
There is no Developer tab and Customize the Ribbon does not help. The workbook may be opened in Protected View (the yellow bar at the top). Click Enable Editing first, then look again.
The editor opens but Run does nothing, or a message says macros are disabled. Check the Trust Center: File > Options > Trust Center > Trust Center Settings > Macro Settings (on Mac, Excel > Preferences > Security). Do not enable all macros blindly — prefer the option to enable macros with notification so you are asked each time. If the settings are greyed out, an administrator controls them and you should ask IT rather than work around it.
You cannot find your code after reopening. The file was probably saved as .xlsx. Reopen the original, save as .xlsm immediately, and paste the code back if you still have the editor open.
The code window is missing but the editor is open. Press Ctrl + R for the Project Explorer, double-click the module name, and the code window appears. If nothing is listed, Insert > Module to create one.
A compile error appears immediately. Check for the red-highlighted line — usually a typo, an unclosed quote, or a missing End Sub. Press the reset button (the small blue square) on the toolbar before running again.
Frequently Asked Questions
Can I use VBA in Excel for the web?
No. Excel for the web can open macro-enabled workbooks and run existing macros in some subscription setups, but it has no VBA editor and cannot create or edit code. Use the desktop app for anything involving the editor.
Is Alt + F11 the same on Mac?
Yes, Alt + F11 opens the editor on Mac too, though many Mac keyboards need Fn held down. The menu route is Tools > Macro > Visual Basic Editor.
Does opening the VBA editor change my file?
Not by itself. Code only becomes part of the file when you save it, and only in a macro-enabled format. Opening and closing the editor without saving leaves the workbook unchanged.
Why can't I see the Developer tab?
It is hidden by default. Right-click the ribbon, choose Customize the Ribbon, tick Developer and click OK. If the workbook is in Protected View, enable editing first.
Can I write macros without the Developer tab?
Yes. Alt + F11 opens the editor and Alt + F8 runs macros regardless of whether the tab is visible. The tab is a convenience, not a requirement.
Are macros a security risk?
They can be, because VBA can read files and change your system. Only enable content in workbooks from sources you trust, and leave macro settings at the default notification level rather than enabling everything.