Generating a List of Macros

by Allen Wyatt
(last updated June 1, 2013)

4

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:

  1. In the VBA Editor, choose References from the Tools menu. The References dialog box is displayed. (See Figure 1.)
  2. Figure 1. The References dialog box.

    ***Insert Figure X –
  3. Scroll through the list of Available References and make sure the Microsoft Visual Basic for Applications Extensibility check box is selected.
  4. Close the dialog box.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing the Height of a Font

Scaling the width of a font is easy to do with Word's formatting capabilities. Scaling the height of the fonts is not so ...

Discover More

Creating Custom Chart Formats

Excel allows you to create custom chart formats that go beyond the standard formats provided in the program. You can then ...

Discover More

Determining Winners, by Category

Do you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...

Discover More

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!

More ExcelTips (menu)

Hiding Macros

Need to hide some macros in your workbook? There are three ways you can do it, as covered in this discussion.

Discover More

One Shortcut for Two Macros

Excel allows you to assign shortcut keys to macros. Given two different workbooks each containing different macros, it is ...

Discover More

Removing a Directory

Macros allow you to perform all sorts of file-related operations. One such operation allows you to delete a directory. This ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three more than 5?

2017-02-23 20:44:33

Jim Percy

My List Macros macro gives many"Worksheet_Selectionchange" lines ?
Otherwise seems OK
Jim Percy


2016-11-19 03:07:10

piecevcake

Thanks -
I ran the sub in personal.xlsb in excel 2007 and it hung - ?


2016-09-25 14:40:33

George Corbett

Alan,
I wanted to thank you very much for your excellent software which lists all macros in an Excel Workbook.

I have been looking for some software to last all macros for quite a while. Yours is the only one which worked,
and it worked the first time out!

I do not understand all that is going on, but it makes no difference as I can now properly document my projects.

Thanks again for a great piece of software.

George Corbett


2015-06-03 16:45:25

Gail

GREAT tip...just what I have been looking for to see all macro names. I have over 200 macros and people are wanting some of them...it's so easy for them to get out of hand. Now I can go in and organize them.
Thank you


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.