sebastienm said:
I believe you'll have to write at least each click event sub, but you can
have it redirected to a common sub
No. As others have suggested, you can use a class module.
As a quick demo, put three ActiveX CheckBoxes on Sheet1 and put this
declaration in a new/blank class module called Class1:
Private WithEvents m_Chk As MSForms.CheckBox
In the code module, drop the (General) dropdown and select the m_Chk
variable. Now in the right hand dropdown (previously Declarations) you
have the control's event handlers. For example, add this code:
Private Sub m_Chk_Click()
MsgBox m_Chk.Name
End Sub
Now imagine you had three instances of this class and the m_Chk.Name
variable was pointing at a different CheckBox for each instance. You'd
need a method to be able to make this association:
Public Function Init(ByVal CheckBox As MSForms.CheckBox) As Boolean
Set m_Chk = CheckBox
End Function
You could use the class in the ThisWorkbook code module like this:
Private Chk1 As Class1
Private Chk2 As Class1
Private Chk3 As Class1
Private Sub Workbook_Open()
Set Chk1 = New Class1
Set Chk2 = New Class1
Set Chk3 = New Class1
Chk1.Init Sheet1.CheckBox1
Chk2.Init Sheet1.CheckBox2
Chk3.Init Sheet1.CheckBox3
End Sub
Run the Workbook_Open sub and now clicking one of the CheckBoxes is
now handled by the same piece of code.
Jamie.
--