dynamic用户表单VBA上的事件

我正在尝试在excel中为dynamic的用户表单分配事件处理程序,让我们只是说我找不到答案,至less我没有办法工作。 我需要在checkbox上处理事件…

Private Sub UserForm_Initialize() Feuil1.Select ThisWorkbook.Generate_Client_List Dim i As Integer i = 1 Dim topref As Integer topref = 25 Dim imgFile1 As Object Set imgFile1 = Client_picking.Controls.Add("Forms.Image.1") With imgFile1 .Left = 140 .Height = 40 .Width = 40 .Picture = LoadPicture("C:\Users\Temp\Desktop\Project\excel.jpg") End With Dim imgFile As Object Set imgFile = Client_picking.Controls.Add("Forms.Image.1") With imgFile .Left = 180 .Height = 40 .Width = 40 .Picture = LoadPicture("C:\Users\Temp\Desktop\Project\mail.jpg") End With Dim Label As Object Set Label = Client_picking.Controls.Add("Forms.Label.1") With Label .Caption = "Clients" .Left = 35 .top = topref - 15 .Width = 90: .Height = 20 .Object.BackStyle = 0 End With For Each distinctClientList In Feuil1.Range("DA3:DA10").Cells Dim MaCheckBox As Object Set MaCheckBox = Client_picking.Controls.Add("Forms.CheckBox.1") With MaCheckBox .Caption = "fichier" .Left = 140 .top = topref + (20 * i) End With Dim MaCheckBoxmail As Object Set MaCheckBoxmail = Client_picking.Controls.Add("Forms.CheckBox.1") With MaCheckBoxmail .Caption = "mail" .Left = 180 .top = topref + (20 * i) End With Dim MaTextBox As Object Set MaTextBox = Client_picking.Controls.Add("Forms.TextBox.1") With MaTextBox .Text = CStr(distinctClientList.Value) .Left = 20 .top = topref + (20 * i) .Width = 90: .Height = 20 End With i = i + 1 Next Dim MyButton As Object Set MyButton = Client_picking.Controls.Add("Forms.CommandButton.1") With MyButton .top = topref + (20 * i) + 20 .Left = 100 .Caption = "Ok" End With Client_picking.Height = topref + (20 * i) + 100 ThisWorkbook.Clear_Client_List ClearToggleList End Sub 

最终的结果是:

该表单包含动态生成的控件列表