VBA-获取组合框的旧值 [英] VBA - Get OLD Value of Combobox
本文介绍了VBA-获取组合框的旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当组合框值更改时,我想获取ComboBox的旧值.
I would like to get the old value of a ComboBox when the combobox value will change.
我尝试过类似的事情:
Private Sub ComboBox1_Change()
Application.EnableEvents = False
newVal = ComboBox1.Value
Application.Undo
oldVal = ComboBox1.Valu
End Sub
或
Private Sub ComboBox1_Change()
Application.EnableEvents = False
newVal = ComboBox1.Value
ComboBox1.Undo
oldVal = ComboBox1.Valu
End Sub
但似乎不起作用...
but it seems not to work...
谢谢
推荐答案
You could use a Static variable that holds its value between calls to the ComboBox1_Change
event:
Private Sub ComboBox1_Change()
Static OldValue As String
With Me.ComboBox1
Debug.Print "Value: "; .Value; " Old Value: "; OldValue
OldValue = .Value
End With
End Sub
如果需要在Change事件之外访问OldValue,请使用模块级变量,如@Ifrandom所述.
If you need to access OldValue outside of the Change event, use a module-level variable, as described by @Ifrandom.
这篇关于VBA-获取组合框的旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文