Listbox of Macros In Workbook

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,060
Hello,
I would like a listbox to list all the macros in the current workbook and then if I click on the macro in the listbox it will then run the macro, can anyone help please
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
The built in Macro dialog box will do that. Use Help to display the Developer tab on the ribbon.
 
Upvote 0
Further to mikerickson's solution - Alt + F8 (i.e. press and hold the Alt key and then press the F8 key) will display the macro dialog in (I believe) any version of Excel.
 
Upvote 0
Thanks guys,

I should have clarified better as to why I want them in a listbox.
I actually want to incorporate it into the listbox as I have other macros in user forms therefore I can then run the macro from the list and then immediately run other macros from user forms rather than have to keep going into the macro list each time opening it and scrolling to a specific macro.
 
Upvote 0
Perhaps this
Code:
Sub test()
    Do
    Loop Until Application.Dialogs(xlDialogRun).Show = False
End Sub
 
Upvote 0
Mike,

Can you please advise how I would make your code work in say Listbox4, so that Listbox4 displays the macros.

Sorry I am not the best with VBA.
 
Upvote 0
My code is to use a native excel dialog box rather than a UserForm. There is no ListBox4. The code can't access the values in the list box.

It seems that you want a listbox of macro names, you select one, press a button and that macro runs.
After the macro has run, you want the same listbox and button visible. Is that right?
 
Last edited:
Upvote 0
Hi Mike,

yes I would like listbox4 on my sheet to list all the macros in the current workbook and then when I click on one of the rows in the listbox I would then click on a commandment button which then activates the selected text/row in the listbox and runs the macro based on the name selected in the listbox.
Sorry I have tried to explain in as much detail as possible and I hope that I haven't confused you more.

I like everything to be on userforms as it makes it much easier when I want to run lots of different macros one after the other, but obviously the order that I run them in changes from project to project.
 
Upvote 0
If you have a listbox from the Forms menu and a list of macro names in its InputRange, assigning the list box to this routine will run the macro when selected by the user.
Note that any list itemst that refer to a macro in a userform's code module need to have a format like "UserForm1.Method22". Unlike macros in normal modules, these get explicit handling, since I can't get them to work with Application.Run.

Code:
Sub ListBox1_Change()
    Dim macroToRun As String
    With ActiveSheet.Shapes(Application.Caller).ControlFormat
        macroToRun = .List(.ListIndex)
    End With
    RunMacroName macroToRun
    ActiveSheet.Shapes(Application.Caller).ControlFormat.ListIndex = 0
End Sub

Sub RunMacroName(macroName As String)
    If CBool(InStr(macroName, ".")) Then
        Rem macros in userforms
        Select Case macroName
            Case "UserForm2.Method21"
                UserForm2.Method21
                Unload UserForm2
            Case "UserForm2.Method22"
                UserForm2.Method22
                Unload UserForm2
            Case "UserForm3.Method333"
                UserForm3.Method333
                Unload UserForm3
            Case Else
        End Select
    Else
        Rem macros in normal modules
            On Error Resume Next
            Application.Run macroName
            On Error GoTo 0
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,254
Messages
6,123,893
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top