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.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
Got a workbook cluttered with all sorts of macros? Delete them and you'll make your workbook easier to manage.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
Excel allows you to assign shortcut keys to macros. Given two different workbooks each containing different macros, it is ...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.