I wrote sub which add checkbox like below
Sub WstawCHB(i As Integer, ByVal ws As Worksheet)
Dim NewCheckBox As MSForms.CheckBox
Set NewCheckBox = ListaObecnosciForm.Controls.Add("Forms.Checkbox.1", "CB" & i, True)
With NewCheckBox
.Top = 20 * i
.Left = 20
.Width = 450
.Height = 24
.Caption = ws.Cells(2 + i, 27)
.Value = False
End With
End Sub
How to add some action to the checkbox in code. For example (.OnAction = "CheckBox1_Click")
Private Sub CheckBox1_Click()
MsgBox "Hello World!"
End Sub
Additional information: the Sub is calling in loop in code below, so I have to "inject" code for every created checkbox for each iteration of loop
Sub DodajCHB(ByVal LW As Integer, ByVal ws As Worksheet)
Dim i As Integer
i = 1
Do While i < LW
Call WstawCHB(i, ws)
i = i + 1
Loop
End Sub