Commandbar - how to find out which msoCommandButton was pressed

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Parameter is what you're after.
I have CommandBar Button examples on my website.
 
Hi Joseph;
Select Case Application.Caller(1)
Case 1
'...
case 2
'...
Case 3
'...
End Select

MP
 
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
 
Back
Top