In Excel for Microsoft 365 on Windows, press Alt+F11 to open the Visual Basic Editor, then use Project Explorer to locate and open the workbook’s VBA module. This lets you inspect or edit macro code; opening the editor does not run the macro. If you use Excel for the web, open the workbook in the desktop app to access VBA.
What You’ll Need
- A desktop version of Excel that supports VBA, such as Excel for Microsoft 365 on Windows or Mac. Excel for the web cannot open or edit VBA code.
- A workbook that contains macros, commonly saved as an Excel Macro-Enabled Workbook (
.xlsm) or Excel Binary Workbook (.xlsb). An older.xlsworkbook may also contain macros. - Permission to view or edit the project. The VBA project may be locked with a password, and a work or school administrator may restrict access.
You do not need to enable macros just to look at their code. If the workbook came from an unfamiliar sender or location, leave macros disabled while you inspect it. Enabling unknown macros can expose your computer and files to harmful code.
Step-by-Step
- Open the workbook in desktop Excel. If it is open in a browser, choose the option to open it in the desktop app, or download it and open it with Excel. VBA projects are not available in Excel for the web. If Excel shows a security warning, do not click Enable Content simply to view the code; the editor can usually be opened while macros remain disabled.
- Check that the workbook can contain VBA. Look at the file extension in the title bar or use File > Info to identify the file. The usual format is
.xlsm. A file ending in.xlsxcannot store VBA macros; if a macro-enabled file was previously saved as.xlsx, Excel may have removed its VBA project. Do not resave an original macro-enabled workbook as.xlsxif you need to preserve its code. - Open the Visual Basic Editor. In Excel for Windows, press
Alt+F11. You can also select Developer > Visual Basic on the ribbon. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon, select the Developer check box under Main Tabs, and select OK. This changes the ribbon display; it does not turn macros on. - Find the workbook in Project Explorer. The editor usually displays Project Explorer along its left side. Look for a project named
VBAProject (YourWorkbookName.xlsm). If the pane is missing, choose View > Project Explorer in the Visual Basic Editor, or pressCtrl+Ron Windows. If several workbooks are open, check each project name so you do not open code from the wrong file. - Expand the workbook project. Select the plus sign beside the project name, or double-click the name if the project is collapsed. You should see folders such as Microsoft Excel Objects and Modules. The exact contents depend on how the workbook was written; a workbook may not have a Modules folder or any standard macros.
- Open a standard module. Expand Modules, if it appears, and double-click a module such as
Module1. Its code opens in the large editor pane. Standard macros often appear here as procedures beginning withSuband ending withEnd Sub. You can scroll through the module or use Edit > Find in the Visual Basic Editor to search for a word or procedure name. - Check the worksheet and workbook objects too. Some VBA is stored outside standard modules. Expand Microsoft Excel Objects and double-click a sheet, such as
Sheet1 (Summary), orThisWorkbook. These code windows can contain event procedures that run in response to actions such as changing a cell or opening the workbook. The object name in parentheses is the visible worksheet name; the name before it is the sheet’s VBA code name. - Use the Macro dialog if you know the procedure name. Close or minimize the editor, return to Excel, and press
Alt+F8on Windows. Select a listed macro and choose Edit to open its code in the editor. This is convenient for a runnable macro, but the list does not show every kind of VBA procedure, including many event procedures and procedures that require arguments. If the macro is not listed, search the project manually instead. - Inspect without making accidental changes. Read the code and note which workbook, sheets, ranges, files, or applications it refers to. To avoid altering the source, close the editor with its close button and choose not to save if prompted after an unintended edit. If you intentionally edit code, save the workbook in a macro-capable format. If you plan to run a macro, first save a separate copy: VBA actions generally cannot be reversed with
Ctrl+Z.
On Mac: Open the Visual Basic Editor with Developer > Visual Basic, or try Option+F11. Depending on the keyboard and macOS settings, you may need Fn+Option+F11 to use the F11 key. The Developer tab may need to be enabled in Excel > Preferences (or Settings) > Ribbon & Toolbar. Ribbon labels and editor layout can differ slightly from Windows, but look for the workbook project, Modules, and Microsoft Excel Objects. VBA editing is not available in Excel for the web on Mac or Windows.
Common Mistakes
- Looking for code in the worksheet grid. VBA is stored in the Visual Basic Editor, not shown as ordinary cell content. Use
Alt+F11on Windows or the Developer tab to open the editor. - Assuming a missing Modules folder means there is no code. Code can be attached to a worksheet or to
ThisWorkbook. Expand Microsoft Excel Objects before concluding that the workbook contains no VBA. - Using Excel for the web. The browser version can preserve a macro-enabled file, but it does not provide the VBA editor. Open the file in desktop Excel to inspect the project.
- Enabling macros to make the editor appear. Macro permissions and access to the code editor are separate. Do not enable code from an untrusted file just to browse it.
- Saving in the wrong format. Saving a macro-enabled workbook as
.xlsxremoves VBA. Keep a working copy in.xlsmor another suitable macro-capable format when preserving the project matters. - Expecting every procedure to appear in Alt+F8. Event code and some other procedures are not offered as runnable macros in that dialog. Locate them in the project tree instead.
Tips
- Use Project Explorer as a map. Standard reusable procedures are commonly in Modules; event-driven code is often attached to a sheet or
ThisWorkbook. This is a useful starting point, not a guarantee, because developers can organize projects differently. - Confirm the active file before editing. Project names include workbook filenames. If you have several workbooks open, expand the project that matches the file you intend to inspect.
- Search before scrolling. In the editor, use Edit > Find to look for a macro name, a distinctive message, or a sheet name. Search the current module first, then broaden the search if the editor offers a scope choice.
- Keep viewing and running separate. Double-clicking a module opens code; it does not execute the procedure. Running code is a separate action and may change data, files, or application settings. Only run code you understand and trust.
- Protect the original. Before editing or running a macro, use File > Save As to make a separate copy. Excel’s normal undo history does not reverse actions performed by VBA, even when the macro changes many cells.
- Be aware of locked projects. A developer can protect a VBA project from viewing. If it is locked, request the password or an unlocked copy from the workbook’s owner rather than trying to bypass the protection.
Troubleshooting
Alt+F11 does nothing: Make sure you are in the desktop version of Excel, not Excel for the web. On Windows, try Developer > Visual Basic. Some laptops require the Fn key for function-key combinations. On Mac, try Developer > Visual Basic or Fn+Option+F11; also check whether the keyboard uses the F keys for system functions.
The Developer tab is missing: On Windows, go to File > Options > Customize Ribbon, select Developer under Main Tabs, and choose OK. On Mac, open Excel > Preferences (or Settings) > Ribbon & Toolbar and enable Developer. If settings are managed by your organization, ask the administrator about restrictions.
Project Explorer is not visible: In the Visual Basic Editor, choose View > Project Explorer. On Windows, Ctrl+R also displays it. If the pane appears but you cannot see the workbook, scroll its list or expand the project tree.
The workbook project is absent or appears empty: Confirm that the correct workbook is open and that it is a macro-capable file. An .xlsx file cannot retain VBA. If you expected code in an .xlsm file, check whether you opened a different copy or whether the code is stored in an add-in or another open workbook. The workbook owner may need to provide the original macro-enabled file.
You can see the project but cannot open its code: The VBA project may be locked for viewing. Excel will ask for its password before showing protected project contents. If you do not have permission or the password, contact the file’s owner. Some workplace security policies may also restrict VBA access.
You opened code but cannot find the macro you expected: Check Modules, all worksheet objects, and ThisWorkbook. Also verify you are viewing the correct project. If the procedure is in an add-in, it may belong to that add-in rather than the workbook. A workbook can also contain no macros even if its filename or instructions suggest otherwise.
Frequently Asked Questions
Can I view macro code without enabling macros?
Usually, yes. Open the Visual Basic Editor and inspect the project while leaving macros disabled. Do not enable content from an untrusted source merely to view the code; a locked project or organizational restriction may still prevent access.
Can I open VBA code in Excel for the web?
No. Excel for the web does not include the VBA editor. Open the macro-enabled workbook in desktop Excel for Windows or Mac to inspect or edit its VBA project.
Why does Alt+F8 not show the macro I am looking for?
The dialog lists macros Excel can run from that interface, not every procedure in a project. Event procedures, procedures that require arguments, and code in a different workbook may not appear. Browse the project tree in the Visual Basic Editor.
Will opening the Visual Basic Editor run the macro?
No. Opening the editor or a code window does not run the procedure. Running a macro is a separate action. Before running one, make sure you trust its source and save a separate copy of the workbook because macro changes generally cannot be undone with Ctrl+Z.
Can I edit a macro in an .xlsx file?
An .xlsx workbook cannot store VBA. If the macro code is in another open workbook or add-in, you may be able to inspect that project, but to preserve VBA in the workbook itself, work with a macro-enabled file such as .xlsm.
Where is code that runs when I change a cell or open a workbook?
Look under Microsoft Excel Objects in Project Explorer. Worksheet event code is associated with the relevant sheet, while workbook-level events are commonly in ThisWorkbook. These procedures may not appear in the Alt+F8 macro list.
Related
- How to Insert a Text Signature in Word Without an Image
- How to Insert a Thick Horizontal Line in Microsoft Word
- How to Insert a Table of Citations in Word
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Macro Recorder Extension: Excel File Types ExplainedExcel does not need a separate macro recorder extension: Microsoft Excel for Microsoft 365 has a built-in recorder…
- Excel VBA Macro to Send a Worksheet File via TeamsYes—but Excel VBA has no built-in command that sends a worksheet directly to Microsoft Teams. A practical Windows…
- Excel Macro Not Working? Find and Fix Common CausesIf an Excel macro is not working, first confirm that the workbook is saved in a macro-enabled format,…
- Refresh Pivot Table Using VBA: Code and TipsTo refresh a PivotTable with VBA in Excel for Microsoft 365 on Windows, call its RefreshTable method; to…
- VBA Show UserForm: Open a Form in ExcelTo show an Excel VBA UserForm, call its Show method, usually from a standard module: UserForm1.Show. In Excel…
- Excel VBA For Loop Backwards: Syntax and ExamplesYes. To run an Excel VBA For loop backwards, use For counter = start To finish Step -1;…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.