vba - ActiveX 组合框不会自动关闭
问题描述
我的ActiveX
Combobox
主工作表中有一个控制/更新一系列图表。
Private Sub cmBoxSelect_GotFocus()
Application.ScreenUpdating = False
With Me.cmBoxSelect
.List = Array("Grand Total", "Prod1", "Prod2", "Prod3", "Prod4", "Prod5")
.ListRows = 6
.DropDown
End With
Application.ScreenUpdating = True
End Sub
Private Sub cmBoxSelect_Change()
'series of codes which manipulates the charts, based on selection...
End Sub
我注意到,当我单击ComboBox
并选择其中一个内容时,它会在所选内容上留下蓝色突出显示。所以为了防止这种情况,我补充说:
Private Sub cmBoxSelect_DropButtonClick()
Application.ScreenUpdating = False
ActiveCell.Activate
Application.ScreenUpdating = True
End Sub
它成功地删除了亮点。
但是,它有一个奇怪的缺点。cmbSelect
一旦用户没有选择任何内容,就不会自动关闭(一旦组合框处于活动状态并且用户单击工作表中的任何单元格,它就不会关闭)。DropButtonClick
在我添加事件之前它正在工作。
我是否错过了上述任何内容或任何错误步骤?感谢您的投入!
编辑#1
似乎我已经通过反复试验找到了解决方案。我只添加了一个空白标签并选择它以在发生更改时将焦点从 ComboBox 中移除。我也将其更改DropButtonClick
为LostFocus
.
Private Sub cmBoxSelect_GotFocus()
Application.ScreenUpdating = False
With Me.cmBoxSelect
.List = Array("Grand Total", "Prod1", "Prod2", "Prod3", "Prod4", "Prod5")
.ListRows = 6
.DropDown
End With
Application.ScreenUpdating = True
End Sub
Private Sub cmBoxSelect_LostFocus()
ActiveCell.Select
End Sub
Private Sub cmBoxSelect_Change()
'series of codes which manipulates the charts, based on selection...
Me.Label1.Select
End Sub
解决方案
让我们试试这个:不是由更改触发的事件,而是由 dropbuttonclick
Private Sub changingComboBox(String s)
'series of codes which manipulates the charts, based on selection...
End Sub
Private Sub cmBoxSelect_DropButtonClick()
Dim s As String
s = cmBoxSelect.SelText
If (cmBoxSelect.SelText = cmBoxSelect.Value) Then
cmBoxSelect.Value = ""
cmBoxSelect.Value = s
Else
call changingComboBox(cmBoxSelect.Value)
End If
End Sub
那个怎么样 ?
推荐阅读
- django - 在不同的 git 分支上迁移后列中的空值
- containers - 如何跨项目访问谷歌容器注册表
- android - 由于自定义构建变体,gradle 任务不明确
- node.js - google oauth 的回调未重定向
- python-3.x - 如何使用 matplotlib 绘制由 KMeans 生成的集群?
- python - 具有三个特征训练的 LSTM,但由于输入形状而无法预测
- excel - Range 类的 Select 方法失败。msgBox 找到范围地址,但不会“.Select”
- typescript - 如何使用异步函数序列化 onNext 调用的 RxJS 订阅?
- javascript - 试图构建一个可以生成图像的网页
- jquery - 使用ajax将字符串传递给控制器