“撤消”comboboxDropButtonClick

我有一系列ComboBoxes是基于前面的ComboBoxselect填充的。 因此,例如, ComboBox3基于在ComboBox2select的值填充。 填充ComboBox3的“触发器”是DropButtonClick操作。 当ComboBox2中没有值时,popup一个消息框。 这是成功的工作 – 代码如下。

 If Me.ComboBox2.ListIndex = -1 Then MsgBox "Please select all preceding comboboxes" ComboBox3.Value = "" Exit Sub Else sh.Range("B2") = Me.ComboBox2.Value End If 

我的问题是一旦Message Box出现(由于ComboBox2中没有值) ComboBox3仍然显示下拉值。 有没有办法在ComboBox3 DropButtonClick Event中没有值时撤消ComboBox3 DropButtonClick Event ,以便ComboBox3永远不会下降?

您可以通过模拟“ESC”键立即closurescombobox的下拉窗口:

  MsgBox "Please select all preceding comboboxes" ComboBox3.Value = "" ' close immediately the combo's dropdown window SendKeys "{ESC}{ESC}" 

这是给你的东西吗?

 If Me.ComboBox2.Value = "" Then ComboBox2.SetFocus Else sh.Range("B2") = Me.ComboBox2.Value End If 

当你想单击combobox3的dropbutton时,它会自动返回到combobox2。