I am modifying the answer in this thread to make it work for my code but it is not working for me.
How to assign an event to multiple objects with excel vba?
A couple of differences, I am using a checkbox instead of a combobox but more importantly, I am creating my checkbox at runtime.
Here is my class:
Public WithEvents checkBox1 As MSForms.checkBox
Private Sub checkBox1_Click()
MsgBox "click"
End Sub'
module code:
Dim tbCollection As New Collection
Sub macro1()
Dim cbox As OLEObject
Dim myCheckBox As New JohnClass
Set cbox = ActiveSheet.OLEObjects.Add("Forms.CheckBox.1", Left:=Range("A1"))
Set myCheckBox.checkBox1 = cbox.Object
tbCollection.Add cbox
end sub
I can see that I have a reference to the newly created check box because I can change the caption but when I click on it, nothing happens.