我有一个使用VBA编写的用于接收实时数据馈送的Excel应用程序。无论何时数据发生变化,VBA内都会触发各种事件。Excel VBA - 更新组合框时暂停事件
我也有一些用户组合框在他们身上。我的问题是,当我单击ComboBox上的向下箭头并尝试进行选择时,从数据源获取更新的那一刻,组合框就会重置。我想要做的是暂停事件,同时在ComboBox中进行选择,然后在完成时取消暂停。我如何生成此功能?
我有一个使用VBA编写的用于接收实时数据馈送的Excel应用程序。无论何时数据发生变化,VBA内都会触发各种事件。Excel VBA - 更新组合框时暂停事件
我也有一些用户组合框在他们身上。我的问题是,当我单击ComboBox上的向下箭头并尝试进行选择时,从数据源获取更新的那一刻,组合框就会重置。我想要做的是暂停事件,同时在ComboBox中进行选择,然后在完成时取消暂停。我如何生成此功能?
也许你可以放弃一个标志绕过更新前夕nt放在组合框上,直到做出选择。
Private bLock as boolean ' declare at module level
' When a user clicks on the combobox
Private Sub DropDownArrow_Click() ' or cboComboBox_Click()
bLocked = True
End Sub
' This procedure is the one that does the updating from the data source.
' If the flag is set, do not touch the comboboxes.
Private Sub subUpdateComboBoxes()
If Not bLocked then
' Update the comboboxes
End If
End Sub
' When the selection is made, or the focus changes from the combobox.
' check if a selection is made and reset the flag.
Private Sub cboComboBox_AfterUpdate() ' Or LostFucus or something else
if Format(cboComboBox.Value) <> vbNullString Then
bLocked = False
End If
End Sub
希望有帮助。
试试这个关闭:
application.enableevents =假
而且这重新打开:
application.enableevents =真
所以,我假设我会成立Application.EnableEvents到ComboBox中DropDownArrow过程内假的,但我不希望重新启用的事件,直到选择后就一直制作 – Shaka 2010-01-13 00:50:49
这将有助于看到你的一些代码真正知道发生了什么。真正的问题是为什么组合框复位?你可以发布代码吗? – guitarthrower 2010-01-13 17:29:25
我能找到问题。我写了一个函数来更新用户表单。显然,该函数还会重置组合框。通过限制对该函数的调用,我能够解决该问题。感谢您指点我正确的方向。 – Shaka 2010-01-22 18:19:39
暂停并显示消息并在暂停期间继续处理某些内容。最后按下按钮
Public Ready As Boolean
Private Sub Command1_Click()
Ready = True
End Sub
Private Sub Form_Load()
Me.Show
Ready = False
Call Wait
Label1.Visible = True
End Sub
Public Function Wait()
Do While Ready = False
DoEvents
Loop
End Function
我能弄清楚是什么导致ComboBox重置,但我绝对喜欢你的解决方案,因为单击向下箭头的行为实际上会暂停更新。感谢您的建议。 – Shaka 2010-01-22 18:25:05