Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Generating a List of Macros.
by Allen Wyatt
(last updated June 18, 2018)
Once you start writing Excel macros, it is easy to get quite a few of them in a workbook. At some point you may want to generate a list of macros in your workbook. There is no intrinsic way within Excel to create a list of macros. You can, however, create a macro that will list your macros. (Sort of sounds redundant, doesn't it?)
As an example, consider the following macro, which steps through all the projects in your workbook to garner all the macro names and place them in a worksheet:
Sub ListMacros() Dim VBComp As VBComponent Dim VBCodeMod As CodeModule Dim oListsheet As Object Dim StartLine As Long Dim ProcName As String Dim iCount As Integer Application.ScreenUpdating = False On Error Resume Next Set oListsheet = ActiveWorkbook.Worksheets.Add iCount = 1 oListsheet.[a1] = "Macro" For Each VBComp In ThisWorkbook.VBProject.VBComponents Set VBCodeMod = ThisWorkbook.VBProject.VBComponents(VBComp.Name).CodeModule With VBCodeMod StartLine = .CountOfDeclarationLines + 1 Do Until StartLine >= .CountOfLines oListsheet.[a1].Offset(iCount, 0).Value = _ .ProcOfLine(StartLine, vbext_pk_Proc) iCount = iCount + 1 StartLine = StartLine + _ .ProcCountLines(.ProcOfLine(StartLine, _ vbext_pk_Proc), vbext_pk_Proc) Loop End With Set VBCodeMod = Nothing Next VBComp Application.ScreenUpdating = True End Sub
In order to use this macro, you must make sure you have the Microsoft VBA extensibility reference set. To do this, follow these steps:
Figure 1. The References dialog box.***Insert Figure X �
When you run the macro, it adds a new worksheet to your workbook, and then lists the names of all the macros in all the modules in the workbook.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2715) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Generating a List of Macros.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
Open up a workbook, and Excel normally runs the macros associated with that workbook. You can disable the automatic ...Discover More
Workbooks get corrupted from time to time; that's a fact of life in an Excel world. If those corrupted workbooks contain ...Discover More
Need a list of macro shortcut keys? It's not as easy in Excel as in some other Office applications, such as Word. It can ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.