我建议不要使用该DropButtonClick
事件。这是另一种选择(方式1),但如果您仍想使用DropButtonClick
,请参阅方式2
方式一
您可以在UserForm_Initialize()
或按钮单击事件中填充组合框。例如
Private Sub UserForm_Initialize()
cmbAdvisor.AddItem ("Test1")
cmbAdvisor.AddItem ("Test2")
End Sub
或者
Private Sub CommandButton1_Click()
cmbAdvisor.Clear
cmbAdvisor.AddItem ("Test1")
cmbAdvisor.AddItem ("Test2")
End Sub
方式二
如果您仍想填充组合框,请DropButtonClick
使用它
Private Sub cmbAdvisor_DropButtonClick()
Dim prevPos As Long
'~~> Get the position of current selection
prevPos = cmbAdvisor.ListIndex
'~~> Switch off event so that when we select an
'~~> item, it doesn't run this proc again
Application.EnableEvents = False
cmbAdvisor.Clear
cmbAdvisor.AddItem ("Test1")
cmbAdvisor.AddItem ("Test2")
'~~> Set the selected value
cmbAdvisor.ListIndex = prevPos
'~~> Reset events
Application.EnableEvents = True
End Sub
在行动