Application.Run"'Macrobook.xlsm'!" Listbox item that is selected

KaibleBasha

New Member
Joined
Aug 8, 2014
Messages
36
Hi,

I am just wondering if there is an easy way to run a macro based on the values within a listbox.

E.g. I have four macros for four reports. I add the names of these reports into a listbox and select them as necessary. How do I then reference them in Application.run or Call?

Item names / Macro names are;
Caseload
TOPs
BBV
MedicalReviews

This is how each item is selected (add = button);
Sub Add_Click()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then ListBox2.AddItem ListBox1.List(i)
Next i
End Sub

I took this from;
Multiple List Box Selections in Excel VBA - Easy Excel Macros

Ideally they would run in sequence, so when one finishes the next in the list runs as I will pre populate the sheets with raw data.

Thanks for any help, & heads up - I am probably going to be slow replying due to work.
Kai
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this:

Code:
Private Sub CommandButton1_Click()
    Dim i As Integer
    For i = 0 To ListBox2.ListCount - 1
        If ListBox2.Selected(i) = True Then
             Application.Run (ListBox2.List(i))
        End If
    Next i      
End Sub
 
Upvote 0
Thanks a lot!

This is working well, however, is there a way to run this without having to have the Item in Listbox2 selected?

Would a change to a default selection after adding to listbox2 be a good enough solution?

Something like;
Sub Add_Click()
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then ListBox2.AddItem ListBox1.List(i)
ListBox2.Selected(i) = True
Next i
End Sub

Thanks again
Kai
 
Upvote 0
Hi,

Sorry I didn't realise that I could apply what you'd sent to a single listbox.

Thanks for the help, I have now just got one list box full of macros that I can run through.

Thanks
Kai
 
Upvote 0

Forum statistics

Threads
1,215,247
Messages
6,123,847
Members
449,129
Latest member
krishnamadison

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