To find VBA code in Excel for Microsoft 365 on Windows, open the workbook in the desktop app, press Alt+F11 to open the Visual Basic Editor, then use Project Explorer to open its modules, worksheet objects, or ThisWorkbook object. If you know a word or procedure name, press Ctrl+F in the editor to search the code. You do not need to run a macro to inspect it; use caution before enabling or running code from a source you do not trust.
What You’ll Need
- The workbook or macro-enabled add-in you want to inspect. Common macro-capable file types include .xlsm, .xlsb, .xlam, and the older .xls format. A regular .xlsx workbook cannot store VBA code, although it can contain buttons or links that point to macros elsewhere.
- The desktop version of Excel. Excel for the web can open and edit many workbook contents, but it cannot open the VBA editor or create, edit, or run VBA macros. If the file is in a browser, use Open in Desktop App.
- Permission to access the VBA project. A project may be password-protected, or your organization may restrict macro access. You can still inspect many workbooks without enabling macros, but protected code may not be viewable.
Step-by-Step
- Open the right file in desktop Excel. Open the workbook that contains, or may contain, the code. Check its extension in File Explorer or use File > Info in Excel to help identify the file. If you have an .xlsx copy and an .xlsm original, inspect the original: saving a macro-enabled workbook as .xlsx removes its VBA project. If the code is in an add-in, open that add-in or make sure it is loaded in Excel. Do not enable content just to look at the code; opening the editor is normally enough to inspect an accessible project.
- Open the Visual Basic Editor. Press Alt+F11 on Windows. Alternatively, select Developer > Visual Basic on the ribbon. If you do not see the Developer tab, right-click the ribbon, choose Customize the Ribbon, select the Developer check box in the main tabs list, and choose OK. In Excel for Mac, use Tools > Macro > Visual Basic Editor, or the Visual Basic command on the Developer tab. The keyboard shortcut can vary with the Mac keyboard and function-key settings; Option+F11, sometimes with Fn, may work. Excel for the web does not provide this editor.
- Show Project Explorer and locate the workbook. In the Visual Basic Editor, press Ctrl+R on Windows if the Project Explorer pane is hidden, or choose View > Project Explorer. On Mac, use the View menu to show Project Explorer. The pane lists open VBA projects, usually with names such as VBAProject (SalesReport.xlsm). Expand the project by clicking its plus sign or disclosure arrow. If several workbooks or add-ins are open, check the name in parentheses so you do not inspect the wrong project.
- Open the likely code locations. Expand Microsoft Excel Objects to see ThisWorkbook and objects named for individual sheets, such as Sheet1 (Summary). Double-click a sheet object to view code attached to that worksheet; double-click ThisWorkbook to view workbook-level event code. Expand Modules and double-click Module1, Module2, or another module to inspect ordinary procedures. If you see Class Modules or Forms, expand those too: code may be stored in a class or attached to a user form. An empty folder or missing module does not prove that the workbook has no code; check the other projects listed in Project Explorer.
- Search the project for a name, phrase, or event. Click inside a code window and press Ctrl+F on Windows. Enter a distinctive word, procedure name, or text fragment, then choose the broadest useful Search scope in the Find dialog, such as Current Project or All Projects if available. Select Find Next to move through matches. Use a short, distinctive phrase if you know one; common words such as Range or Cells can return many results. Searching for a sheet name, a button caption, or a distinctive message shown by the workbook can help connect an action to its procedure.
- Check how the code is triggered. A macro listed in the Alt+F8 Macro dialog is usually a public procedure stored in a standard module, but that dialog does not list every kind of VBA code. Worksheet events such as Worksheet_Change live in that sheet’s code window, while workbook events such as Workbook_Open live in ThisWorkbook. For a Form Control button, right-click it on the worksheet and choose Assign Macro to see its assigned procedure; cancel or close the dialog without changing the assignment. For an ActiveX control, turn on Developer > Design Mode, right-click the control, and choose View Code. Event-driven code may run in response to a change, opening the file, or clicking a control even though it does not appear in the Macro dialog.
- Read the procedure without running it. Click in the code window and inspect the procedure name and nearby comments. The dropdowns at the top of a code window can help you navigate to an object and its event procedure. If the editor displays a password prompt for the VBA project, you need the project owner or administrator to provide authorized access; do not try to bypass the protection. If you intend to test or change a macro, save a separate copy first. Macro actions cannot be undone with Ctrl+Z, and even a small test can change or delete workbook data.
Common Mistakes
Looking only in the Macro dialog: Alt+F8 is useful for finding runnable public macros, but it omits many event procedures, private procedures, and code attached to worksheet or workbook objects. Inspect those objects in Project Explorer as well.
Searching the wrong project: The editor may show several open workbooks, PERSONAL.XLSB, or add-ins. A macro can be stored outside the workbook you are viewing. Confirm the project name and search other open projects when the expected code is not in the file.
Assuming the Developer tab is required: The tab is a convenient route, but Alt+F11 opens the editor directly on Windows. If the shortcut is intercepted by a laptop’s function-key settings, use the ribbon command instead.
Confusing a macro button with the macro code: A worksheet button is a control, not the procedure itself. Find its assigned macro, then locate that procedure in the relevant VBA project. A button may also call a procedure in PERSONAL.XLSB or an add-in.
Saving a macro file as .xlsx: This format cannot preserve VBA. Keep the original macro-enabled file, or save a copy in a macro-capable format such as .xlsm when appropriate. Do not overwrite the only copy while experimenting.
Tips
- Use Ctrl+F for targeted searches and Ctrl+H only when you deliberately need to find and replace code text. Review every match before changing anything.
- Search for an event name when you suspect automatic behavior. Examples include Worksheet_Change, Worksheet_SelectionChange, and Workbook_Open. These are procedure names to look for, not commands to type into a worksheet.
- If you know the worksheet involved, open that sheet’s object before searching. Event code is often stored there rather than in a standard module.
- Use the Project Explorer and Properties window together to identify sheet objects. The visible worksheet tab name and the object name shown in the editor can differ.
- Code may be difficult to read if it is long or split among several procedures. Follow procedure calls by searching for the called procedure name, and note which workbook or add-in contains each match.
- Keep macros disabled unless you trust the file and have a reason to run them. Inspecting code is not a guarantee that a workbook is safe, and unfamiliar code can have effects beyond the visible sheet.
Troubleshooting
Alt+F11 does nothing: Try Developer > Visual Basic. If Developer is missing, enable it through Customize the Ribbon as described above. On some keyboards, a function-key setting or another application intercepts the shortcut. On Mac, use the Tools menu or Developer tab; Excel for the web requires opening the workbook in the desktop app.
Project Explorer is missing: In the Visual Basic Editor, choose View > Project Explorer, or press Ctrl+R on Windows. If the pane appears but its contents are collapsed, expand the project and its folders.
The workbook project is not listed: Confirm the workbook is open in desktop Excel and that you are looking at the correct editor instance. Check whether the code is in another open workbook, PERSONAL.XLSB, or an installed add-in. If the file is .xlsx, it cannot contain a saved VBA project; look for the original macro-enabled copy or an external add-in.
Search finds nothing: Search a shorter distinctive phrase, check spelling and the selected scope, and search each relevant project. Code may construct a displayed message in pieces, so the full phrase might not appear exactly as shown. Also check sheet and ThisWorkbook objects for event code.
The code window is blank or asks for a password: Confirm you opened the correct object and project. If the project is locked, ask its owner for access. A blank procedure window may simply mean that object has no code; check modules and other objects before concluding that the whole workbook is code-free.
A macro is missing from Alt+F8: Look for event procedures, private procedures, macros that require arguments, and code in another workbook or add-in. The Macro dialog is not a complete inventory of all VBA code.
Frequently Asked Questions
Can I find VBA code without running the macro?
Yes. Open the Visual Basic Editor and inspect the project without running its procedures. You generally do not need to enable macros just to view accessible code. Do not run unfamiliar code merely to identify it.
Can I view VBA code in Excel for the web?
No. Excel for the web does not include the Visual Basic Editor. Open the workbook in desktop Excel for Windows or Mac to inspect VBA. The browser version may preserve a macro-enabled workbook, but it cannot show or edit its VBA code.
Why does a workbook have buttons but no code in its project?
The button may point to a macro in another open workbook, PERSONAL.XLSB, or an add-in. It could also be a control without an assigned macro, or the file may be an .xlsx copy that no longer contains its original VBA. Check the button assignment and other projects.
Does Alt+F8 show every macro in a workbook?
No. It mainly lists eligible public procedures that can be run directly. Worksheet and workbook events, private procedures, and procedures that require arguments may not appear. Browse the project objects and modules to find these.
What if the VBA project is locked?
You can ask the workbook’s owner or administrator for the password or an unlocked copy. If the project is protected, Excel will not show its code without authorized access. Do not try to circumvent the protection.
Can I edit the code after I find it?
Yes, if the project is accessible and you have permission, but save a separate copy before editing or testing. A macro can change workbook data, and its actions cannot be reversed with Ctrl+Z. Keep the original file intact.
Related
- Excel Solver: Find Numbers That Sum to a Value?
- Excel Solver: Find Combinations That Sum to a Target
- Excel Slicers Explained: Filtering PivotTables and Tables
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Date Difference: Calculate Days and MonthsIn Excel VBA, use DateDiff to count calendar boundaries between two dates, for example DateDiff("d", startDate, endDate) for…
- How to Run Macros in Google Sheets: A Step-by-Step GuideTo run a macro in Google Sheets, open the spreadsheet in a desktop web browser, choose Extensions >…
- Excel VBA Filter Function: Syntax, Examples, and LimitsIn Excel VBA, the Filter function searches a one-dimensional array of strings and returns the elements that contain…
- Filter Dictionary Keys in Excel VBA: Code and OptionsYes. In Excel VBA, filter a Scripting.Dictionary by looping through its keys and copying the matching key/value pairs…
- VBA MsgBox Sound: What Triggers It and How to Control ItIn Excel VBA, MsgBox has no argument for choosing or setting a sound. On Windows, a message box…
- Excel VBA: Filter a PivotTable by Field or ValueYes. In Excel VBA, filter a PivotTable by setting a report-filter field’s CurrentPage, applying a label or value…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.