You open the VBA editor in Excel with a keyboard shortcut or a ribbon button: press Alt + F11 on Windows, or go to Developer > Visual Basic. On a Mac, press Option + F11 or use Tools > Macro > Visual Basic Editor. If the Developer tab is missing, you need to enable it once via Excel Options. Once the editor is open, you can view, edit, and run the macros stored in the workbook, including those saved in modules, sheet objects, and ThisWorkbook.

The VBA editor (also called the Visual Basic Editor, or VBE) is a separate window that ships with every desktop copy of Excel. It is not available in Excel for the web, and mobile versions cannot open or edit VBA. This guide focuses on the Windows desktop version, with notes for Mac where the steps differ. Exact labels can differ slightly by version and region.

What You'll Need

  • Excel for Windows or Mac installed on your computer (not the browser or mobile app).
  • A workbook that contains macros — usually saved as .xlsm, .xlsb, or .xls — or permission to create new ones.
  • Macro security settings that allow you to view and run code. Forcing macros to run from an untrusted file is a security risk, so only open workbooks from sources you trust.
  • Optional: the Developer tab enabled on the ribbon, which makes the most common VBA commands one click away.

Step-by-Step

  1. Open the workbook that contains the code. Launch Excel and open your .xlsm file. If you see a yellow security warning bar saying macros have been disabled, that is normal. You can still inspect the code without enabling macros.
  2. Enable the Developer tab if it is hidden. Right-click any empty area of the ribbon and choose Customize the Ribbon. In the list on the right, tick the box next to Developer, then click OK. On Mac, open Excel > Preferences > Ribbon & Toolbar, tick Developer and confirm. On newer Mac builds the option sits under Settings instead of Preferences.
  3. Open the VBA editor. Press Alt + F11 on Windows, or Option + F11 / Fn + Option + F11 on some Mac keyboards. Alternatively, click Developer > Visual Basic. A separate window opens; it may appear behind the main Excel window, so check your taskbar or use Alt + Tab.
  4. Find the code module. In the top-left Project Explorer pane, expand your workbook name and look inside the Modules or Microsoft Excel Objects folders. Double-click a module (for example, Module1) to open its code in the large pane on the right. Sheet-specific code lives under objects named like Sheet1, and workbook-level events live in ThisWorkbook.
  5. Read the code. Click anywhere in the code pane to place your cursor, then scroll through the listing. You can expand the drop-down boxes at the top of the pane to see the object and procedure you are looking at. Comments appear in green and begin with an apostrophe.
  6. Step through or run it safely. To pause execution at a line, click in the grey margin beside a line of code to set a breakpoint (a red dot). Then press F5 to run or F8 to step through one line at a time. To stop, use the square Reset button on the toolbar. Always save a copy of the workbook before running code you did not write.
  7. Close the editor when finished. Either click the X on the VBA window or press Alt + F4. Any changes you made are held in memory until you save the workbook in a macro-enabled format.

If you only need to see macros attached to buttons or run a quick one-off task, the other route is Developer > Macros (or Alt + F8). That dialog lists recorded macros and lets you run or step into them, but it does not show code that is not attached to a macro name, such as event handlers.

Common Mistakes

  • Looking in the wrong Office app. The VBA editor belongs to the app that is hosting it. If you opened the code from Word, the Project Explorer shows Word documents, not workbook modules. Make sure you launched it from Excel.
  • Confusing the editor with the Macro dialog. Alt + F8 is a list of macros; Alt + F11 is the actual code editor. If the pane on the right is empty, you likely have no module selected in the Project Explorer.
  • Saving as .xlsx. A standard .xlsx file cannot store macros. If you paste in code and save as .xlsx, Excel warns you and the code is stripped. Use .xlsm instead.
  • Editing protected code. A VBA project password or a locked workbook will block the code from showing. You will get a password prompt or an error when you try to expand the project.
  • Expecting it to work in the browser or on a phone. Excel for the web and the mobile apps have no VBA editor. Use the desktop app.

Tips

  • Keep the Immediate Window visible (Ctrl + G on Windows) for quick tests, such as typing ?Range("A1").Value to check a cell's contents.
  • Use View > Properties Window if your panes get hidden; the Project Explorer can be restored from the same View menu.
  • In the editor, Tools > Options lets you turn on line numbers in the Code Settings, which helps when reading long routines.
  • If you plan to run code often, add a button to the Quick Access Toolbar that points to Visual Basic so a single click opens it.
  • Before reviewing unfamiliar code, save a copy of the file. Some routines change cells, delete sheets, or save over the workbook.

Troubleshooting

Alt + F11 does nothing. Another app may be capturing the shortcut, or the workbook window may not have focus. Click inside the Excel window first, then try again. On Windows laptops, some keyboard drivers intercept F11 or require Fn. Try Developer > Visual Basic instead.

The Developer tab is missing and the right-click option does not appear. Make sure you are not in a read-only or protected view window; close the file and reopen it normally. Also confirm you are in the desktop app, not the browser.

I can see the editor but the code is empty. Expand every folder in the Project Explorer and double-click each module. Code can sit inside ThisWorkbook or a sheet object rather than a standard module. If everything is empty, the workbook may not actually contain macros.

I get a password prompt. The VBA project is locked by its author. There is no supported way around that password; ask the file's owner for access or for an unprotected version.

I get a security warning about macros. Do not use the file if you do not trust its source. If you do trust it, open it from a location marked as trusted in File > Options > Trust Center > Trust Center Settings > Trusted Locations. Never lower macro security globally just to open one unknown file.

My code disappears after saving. You saved to .xlsx or the file was blocked. Reopen the original .xlsm, re-paste the code, and use File > Save As with Excel Macro-Enabled Workbook selected.

Frequently Asked Questions

Can I open the VBA editor in Excel for the web or on a phone?

No. The VBA editor is only in the desktop apps for Windows and Mac. Browser and mobile versions cannot view or edit VBA code.

Why does the editor open behind Excel?

It is a separate window and some systems do not bring it to the front. Use Alt + Tab or click its taskbar icon. Pressing Alt + F11 again usually toggles it back.

Can I view code without enabling macros?

Yes. The editor will display the code stored in the file, but nothing executes until you run it. Enabling macros only matters when you want to run them.

Where does recorded macro code go?

When you record a macro, it is saved in a new module inside the workbook, or in your Personal Macro Workbook if you choose that in the Record Macro dialog. Open the editor and look under Modules to find it.

Does opening the editor change my file?

Viewing code does not change your workbook, but editing it does. Any edits stay in memory until you save, so close without saving if you only wanted to look.

Is it safe to run macros from a downloaded file?

Only if you trust the source. Macros can modify files and access other data on your computer. Treat unexpected macro-enabled attachments as suspicious and do not enable content from senders you do not know.