AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 1,822
- Office Version
- 2019
- 2016
- Platform
- Windows
I'm wanting what I think would be a Command Button Control Array.
Where a number of buttons can share a common click event and pass something to identify which button was clicked.
I found this via Google
However I can't get this to work. Perhaps something is missing?
Any help with this or alternative method appreciated.
Thanks
Where a number of buttons can share a common click event and pass something to identify which button was clicked.
I found this via Google
Code:
Private arCommandButton(1 To 3) As New Class1
Private Sub init()
Set arCommandButton(1).ButtonEvents = cmd1
arCommandButton(1).Index = 1
Set arCommandButton(2).ButtonEvents = cmd2
arCommandButton(2).Index = 2
Set arCommandButton(3).ButtonEvents = cmd3
arCommandButton(3).Index = 3
End Sub
'In a Class Module
Public WithEvents ButtonEvents As MSForms.CommandButton
Public Index As Integer
Private Sub ButtonEvents_Click()
MsgBox "Button clicked. The Index is: " & Index
End Sub
However I can't get this to work. Perhaps something is missing?
Any help with this or alternative method appreciated.
Thanks