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

Increasing Envelope Address Lines

Envelopes in Word are created through the use of styles that define specific elements of the envelope, such as return address ...

Discover More

Unique Military Date Format

Some industries (such as the military) have special formatting that they use to represent dates. Here is one such format and ...

Discover More

Changing the Style Area Font

The style area, displayed at the left side of your document, can be helpful in understanding how styles are used in your ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Disabling Shift Key Use when Opening a Workbook

Open up a workbook, and Excel normally runs the macros associated with that workbook. You can disable the automatic running ...

Discover More

Renaming a File

Need to rename a file in a macro? It's easy to do using the Name command, as discussed in this tip.

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
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. 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 2 + 1?

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.