Results 1 to 6 of 6

Thread: Macro Name List

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Macro Name List

    Right now, I have a worksheet with lots of macro (around 20)

    Is there any code such that I could use a macro to list the names of all macro in the sheet automatically??

    Many Thanks,

  2. #2
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Here's one... [vba]Option Explicit

    Sub ListOfMacros()
    On Error Resume Next '< error = reference already set
    'set reference to Microsoft Visual Basic for Applications
    'Extensibility 5.3
    ThisWorkbook.VBProject.References.AddFromGuid _
    "{0002E157-0000-0000-C000-000000000046}", 5, 3
    'now get the list of macros
    Call GetTheList
    End Sub

    Private Sub GetTheList()
    Dim N As Long, Count As Long, MyList(200), List As String
    Dim Component As VBComponent
    For Each Component In ActiveWorkbook. _
    VBProject.VBComponents
    With Component.CodeModule
    Count = .CountOfDeclarationLines + 1
    Do Until Count >= .CountOfLines
    MyList(N) = .ProcOfLine(Count, _
    vbext_pk_Proc)
    Count = Count + .ProcCountLines _
    (.ProcOfLine(Count, vbext_pk_Proc), _
    vbext_pk_Proc)
    List = List & vbCr & MyList(N)
    If Count < .CountOfLines Then N = N + 1
    Loop
    End With
    N = N + 1
    Next
    MsgBox List, , "List of Macros"
    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  3. #3
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,321
    Location
    I see John has already posted here but I am going to attach a file that John shared some time back that I have found useful for just such cases as this...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4

    List of Macro Name List

    Thanks, however, I cannot run this macro.

    Is there any special component for me to install in order to run this macro??

    Many Thanks,

  5. #5
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,321
    Location
    Quote Originally Posted by JuniorASA
    I cannot run this macro.
    I'm gonna have to get Gerry after you(Inside joke for the regulars of the forum-from the word forum). What does that mean? Did you get a security warning when you opened the workbook or did you get an error when you ran it? If so what was the error?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,321
    Location
    You will also have to go to tools-macro-security
    click on the trusted Publishers tab at the top
    be sure the box marked "Trust access to visual basic project" is checked
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •