Private Sub CommandButton1_Click()
' ...
End Sub
Private Sub CommandButton2_Click()
' ...
End Sub
Private Sub CommandButton3_Click()
' ...
End Sub
' etc.
Private Sub CommandButton1_Click()
MsgBox "Button 1 was clicked"
End Sub
Private Sub CommandButton2_Click()
MsgBox "you clicked #2"
End Sub
Private Sub CommandButton3_Click()
MsgBox "three"
End Sub
' etc.
Yes I know the solution you suggest.
But I am looking if there is an other way to solve this.
Dim colButton As Collection 'Collection of Button 'This to the top of all the code.
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim clsObject As Class1
'Create New Collection To Store Custom
Set colButton = New Collection
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CommandButton" Then
Set clsObject = New Class1
Set clsObject.Button = ctrl
colButton.Add clsObject
End If
Next
End Sub
Public WithEvents Button As MSForms.CommandButton
Private Sub Button_Click()
MsgBox "you clicked button : " & Button.Caption
End Sub
Dim colButton As Collection 'Collection of Button 'This to the top of all the code.
Private Sub UserForm_Initialize()
Dim ctrl As MSForms.Control
Dim clsObject As Class1' get massage "not defifned"
'Create New Collection To Store Custom
Set colButton = New Collection
For Each ctrl In Me.Controls
If TypeName(ctrl) = "cmb" Then
Set clsObject = New Class1
Set clsObject.Button = ctrl
colButton.Add clsObject
End If
Next
End Sub