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

Leaving a Cell Value Unchanged If a Condition Is False

Ever want the IF function to only return a value if the condition it is testing is true, and not if the condition is false? ...

Discover More

Open Workbooks Don't Display

Have you ever opened a workbook, only to have it not display your worksheet data? This can be very disconcerting, but it ...

Discover More

Starting in Safe Mode

By using a command-line switch, Excel can be started in safe mode. This means that the program is loaded with bare-bones ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

MORE EXCELTIPS (MENU)

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

Aborting a Macro and Retaining Control

If you need to exit a macro before it is finished running, you can do it using a brute force method, or you can build in a ...

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 for this tip:

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 7 + 8?

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


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.

Links and Sharing
Share