我正在尝试在excel中的动态用户表单上分配事件处理程序,让我们说我找不到答案,至少我无法开始工作。我需要在复选框上处理事件......
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
最终结果: