This guide shows how to generate a complete list of all VBA modules (standard, class, and worksheet/workbook modules) and their procedures (Subs and Functions) in the active Excel workbook. No add-ins or external tools are required—just a short VBA macro that reads the VBA project directly. Note: you must enable programmatic access to the VBA project (via Trust Center settings), and the workbook must contain VBA code for meaningful output.
What You'll Need
- A Windows version of Microsoft Excel (Excel for Mac supports VBA but the VBE object model is more limited; steps below assume Windows)
- Excel file with at least one VBA module or procedure (optional, but the macro will produce an empty list if none exist)
- Enabled macro settings: Trust access to the VBA project object model (required)
Step-by-Step
- Open the Excel workbook containing the VBA code you want to audit.
- Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
- In the VBA editor, go to Tools > References. Ensure Microsoft Visual Basic for Applications Extensibility 5.3 is checked (if missing, scroll down and select it, then click OK). This reference allows the macro to access the VBA project structure.
- Close the References dialog.
- Press Alt + F8 to open the Macro dialog. Type a name for your new macro—e.g.,
ListAllProcedures—and click Create. This opens the VBA editor with a new empty module. - Paste the following complete macro into the new module:
Sub ListAllProcedures() Dim vbProj As Object Dim vbComp As Object Dim procName As String Dim procKind As Long Dim ws As Worksheet Dim i As Long Dim lineNum As Long ' Validate VBA project access On Error GoTo VBAProjectError Set vbProj = ThisWorkbook.VBProject ' Create or clear output sheet On Error Resume Next Application.DisplayAlerts = False ThisWorkbook.Worksheets("VBA Procedures").Delete Application.DisplayAlerts = True On Error GoTo 0 Set ws = ThisWorkbook.Worksheets.Add ws.Name = "VBA Procedures" ' Header row ws.Range("A1").Value = "Module Name" ws.Range("B1").Value = "Procedure Name" ws.Range("C1").Value = "Type" ws.Range("D1").Value = "Start Line" ws.Range("A1:D1").Font.Bold = True ws.Range("A1:D1").Interior.Color = RGB(200, 200, 200) i = 2 ' Loop through all components in the project For Each vbComp In vbProj.VBComponents ' Skip Designer components (e.g., UserForm designers) If vbComp.Type <> 101 Then ' Loop through all procedures in the component On Error Resume Next ' Some components (like worksheets) may have no Count property For procName = 0 To vbComp.CodeModule.CountOfLines ' Get procedure info procKind = vbComp.CodeModule.ProcKindOfLine(procName, 0) If procKind > 0 Then ' Only record actual procedures (not line numbers for declarations) If procName > 0 Then ws.Cells(i, 1).Value = vbComp.Name ws.Cells(i, 2).Value = vbComp.CodeModule.ProcOfLine(procName, 0) Select Case procKind Case 1: ws.Cells(i, 3).Value = "Sub" Case 2: ws.Cells(i, 3).Value = "Function" Case 3: ws.Cells(i, 3).Value = "Property Let" Case 4: ws.Cells(i, 3).Value = "Property Get" Case 5: ws.Cells(i, 3).Value = "Property Set" Case 6: ws.Cells(i, 3).Value = "Event" Case Else: ws.Cells(i, 3).Value = "Unknown" End Select ws.Cells(i, 4).Value = vbComp.CodeModule.ProcStartLine(procName, 0) i = i + 1 End If End If Next procName On Error GoTo 0 End If Next vbComp ' Auto-fit columns ws.Columns("A:D").AutoFit MsgBox "List complete. Found " & (i - 2) & " procedures.", vbInformation, "VBA Audit" Exit Sub VBAProjectError: MsgBox "Error accessing VBA project. " & _ "Go to File > Options > Trust Center > Trust Center Settings > Macro Settings " & _ "and check 'Trust access to the VBA project object model'.", vbCritical, "Access Denied" End Sub - Save the workbook as a macro-enabled file (.xlsm) if prompted.
- Press F5 (or click Run) while the cursor is inside the
ListAllProceduresmacro to execute it. - Check the newly created "VBA Procedures" worksheet in your workbook. It will list every module name, procedure name, type (Sub/Function/etc.), and starting line number.
Common Mistakes
- Forgetting to add the Microsoft Visual Basic for Applications Extensibility 5.3 reference—this causes a compile error like "User-defined type not defined".
- Running the macro without enabling macros or disabling all macros (the file must be .xlsm and macros must be enabled).
- Not checking Trust access to the VBA project object model in Trust Center settings—this is the most frequent cause of the "Access Denied" error.
- Using the macro on a workbook with no VBA code—it will still create the sheet, but it will be empty (only headers), which may be mistaken for failure.
- Running the macro on a workbook open in a protected view or read-only mode—Excel may block VBA modifications.
Tips
- Run the macro on a copy of your workbook if you're unsure—this avoids accidental changes to your main project.
- Press Ctrl + Shift + L after running to apply an AutoFilter to the list, making it easy to sort by module or procedure type.
- For large projects, disable screen updating at the start (
Application.ScreenUpdating = False) and re-enable at the end to speed up execution. - To export just procedure names (e.g., for documentation), modify the macro to write only columns A and B.
- Use the
ProcCountOfLinesandProcStartLineproperties to count lines per procedure if you need complexity metrics.
Troubleshooting
If the macro fails, follow these steps in order:
- Check macro security: Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Ensure Enable all macros is selected (for development only—revert later for security) and Trust access to the VBA project object model is checked.
- Restart Excel—sometimes the VBA project lock persists across sessions until Excel is fully closed and reopened.
- Verify the reference: In the VBA editor, go to Tools > References. Confirm Microsoft Visual Basic for Applications Extensibility 5.3 is listed and checked. If not, scroll to it, check it, and click OK.
- Test with a simple workbook: Create a new workbook, insert one standard module, add a dummy
Sub Test(), and run the macro. If it works here, the issue is likely with your original workbook (e.g., corruption or protection). - Check for VBA project password: If the VBA project is password-protected, you must enter the correct password before the macro can read it. Without the password, no code can access the project structure.
- Use error handling: If the macro crashes mid-run, add
Debug.Print vbComp.Namebefore the procedure loop to identify which component is causing the error.
Frequently Asked Questions
Will this list procedures in UserForms?
Yes—the macro includes procedures in all components (standard modules, class modules, worksheet modules, and UserForm modules), as long as they are part of the VBA project.Can I list procedures from all open workbooks, not just the active one?
Yes, but you’ll need to loop throughApplication.Workbooks and run the macro for each workbook’s .VBProject. The current code targets ThisWorkbook, so change ThisWorkbook.VBProject to Workbooks("YourFile.xlsx").VBProject for a specific file, or wrap the logic in a loop over open workbooks.
Does this work on Excel for Mac?
Partially. Excel for Mac does not support the VBA extensibility library in the same way, andVBProject access is often blocked by default. This macro is designed for Windows Excel and is not guaranteed to run on Mac.
What if I get a "Run-time error '5': Invalid procedure call or argument"?
This often occurs when trying to read the procedure count of worksheet or workbook modules. The macro includesOn Error Resume Next to skip those, but if you see it, ensure you’re using the exact code provided. Also, check that no module has a syntax error—fix any compile errors first by clicking Debug > Compile VBA Project.
Can I export this list to a text file instead of a worksheet?
Yes—modify the macro to useOpen and Print # statements to write to a .txt file instead of worksheet cells. Replace the ws.Cells(i, x).Value = ... lines with file write commands. You’ll need to manage file paths and closing the file handle.