Commandbar - how to find out which msoCommandButton was pressed

G

Guest

I have own CommandBar "MyMenu" with three msoCommandButton. Each
CommandButton runs the macro, I change only the rowsource for UserForm. E.g.
CommandButton(1) runs MyMacro1 with setting the rowsource="range1",
CommandButton(2) runs MyMacro2 with setting the rowsource="range2". I have
for each CommandButton own macro. Is some way how to find out which
CommandButton was pressed and this argument I can use in next code.

myPressButton = 'which CommandButton was pressed '
Sub MyMacroAll
Select Case myPressButton
Case ?: UserForm1.rowsource = "range1"
Case ??: UserForm1.rowsource = "range2"
End Select
End Sub
 
R

Rob van Gelder

Parameter is what you're after.
I have CommandBar Button examples on my website.
 
M

Michel Pierron

Hi Joseph;
Select Case Application.Caller(1)
Case 1
'...
case 2
'...
Case 3
'...
End Select

MP
 
T

Tom Ogilvy

I think the best answer is

set cb = CommandBars.ActionControl

If you need a case statement you could use

Userform1.Load
Select Case cb.Caption
Case "Button1"
Userform1.Listbox1.RowSource = "Sheet1!A1:A10"
Case "Button2"
Userform1.Listbox1.RowSource = "Sheet1!B1:B10"
End Select
Userform1.Show
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top