Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default how to assign sub routines to events

hello,

I was wondering if it is possible to assign a custom routine to a click
event for example? More importantly, is it possible to pass args with these
custom events?

Basically I have 30 buttons that do essentially the same thing. They are
only different depending on which button you press. So if I can create a
custom routine which passes the button number that would be ideal.


  #2   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default how to assign sub routines to events

Have all of the buttons reference the same sub or routine and have the action
based on the name of the button.



"mrengc" wrote:

hello,

I was wondering if it is possible to assign a custom routine to a click
event for example? More importantly, is it possible to pass args with these
custom events?

Basically I have 30 buttons that do essentially the same thing. They are
only different depending on which button you press. So if I can create a
custom routine which passes the button number that would be ideal.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default how to assign sub routines to events

Add this code to the sheet with the buttons on

Option Explicit

Dim mcolEvents As Collection

Private Sub Worksheet_Activate()
Dim cBtnEvents As clsActiveXEvents
Dim shp As Shape

Set mcolEvents = New Collection

For Each shp In Me.Shapes
If shp.Type = msoOLEControlObject Then
If TypeOf shp.OLEFormat.Object.Object Is MSForms.CommandButton
Then
Set cBtnEvents = New clsActiveXEvents
Set cBtnEvents.mButtonGroup = shp.OLEFormat.Object.Object
mcolEvents.Add cBtnEvents
End If
End If
Next

End Sub


and then insert a class module, call it clsActiveXEvents, with this code

Option Explicit

Public WithEvents mButtonGroup As MSForms.CommandButton

Private Sub mButtonGroup_Click()
MsgBox mButtonGroup.Caption & " has been pressed"
End Sub


--
HTH

Bob Phillips

"JNW" wrote in message
...
Have all of the buttons reference the same sub or routine and have the

action
based on the name of the button.



"mrengc" wrote:

hello,

I was wondering if it is possible to assign a custom routine to a click
event for example? More importantly, is it possible to pass args with

these
custom events?

Basically I have 30 buttons that do essentially the same thing. They

are
only different depending on which button you press. So if I can create

a
custom routine which passes the button number that would be ideal.




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
VBA - sub routines Help please Richard Wrigley New Users to Excel 3 November 23rd 06 03:06 AM
VBA routines - help please Richard Wrigley Excel Discussion (Misc queries) 1 November 22nd 06 07:15 PM
Calling sub routines Andrew[_49_] Excel Programming 2 June 30th 05 05:30 PM
vb dummy - two routines Greg Excel Programming 6 June 20th 05 04:56 PM
Removing VBA routines Robin Clay[_2_] Excel Programming 2 October 14th 03 05:44 PM


All times are GMT +1. The time now is 08:26 PM.

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"