我有一個使用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