Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Commandbar - how to find out which msoCommandButton was pressed

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Commandbar - how to find out which msoCommandButton was pressed

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

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"JosephVBA" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Commandbar - how to find out which msoCommandButton was pressed

Try again... post seems to delete itself from the server.
---
Parameter is what you're after.
I have CommandBar Button examples on my website.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"JosephVBA" wrote in message
...
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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default Commandbar - how to find out which msoCommandButton was pressed

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

MP

"JosephVBA" a écrit dans le message de
...
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Commandbar - how to find out which msoCommandButton was presse

Thanks, it seems like a good solution. I`ll try it later.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Commandbar - how to find out which msoCommandButton was pressed

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
--
Regards,
Tom Ogilvy


"JosephVBA" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If pressed no to msgbox, then exit sub Hari[_3_] Excel Programming 5 January 17th 05 02:52 PM
Delete is Pressed then Stop Lenny_821 Excel Programming 1 October 11th 04 12:56 PM
Which button was pressed? Adrian[_4_] Excel Programming 7 April 28th 04 04:55 PM
Errormessage when button is pressed twice or more Pointerman Excel Programming 4 April 7th 04 03:56 PM
Trapping key pressed in a worksheet John[_35_] Excel Programming 1 February 28th 04 05:46 AM


All times are GMT +1. The time now is 03:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"