我有一个Worksheet_BeforeDoubleClick
事件检查,看看广告点击一个细胞是否具有在一个Dictionary对象,像这样的数据:如何存储可用于多次事件调用的对象?
Private Sub Worksheet_BeforeDoubleClick(ByVal Target as Range, Cancel as Boolean)
Dim dict as Dictionary
Dim df as New dictFactory
'returns a dictionary populated with all list items
Set dict=df.create
If dict.Exists(Target.Value) Then
MsgBox "Exists"
Else
MsgBox "Doesn't exist"
End If
End Sub
的问题是,这需要创建一个新的字典中的每个被点击的单元时间。我认为这将是很好的存储字典中的全局变量自己的模块中,像这样:
Global valuesDict As New Dictionary
,然后填充它在打开的工作簿:
Private Sub workbook_open()
Dim df as New dictFactory
Set valuesDict=df.create
End Sub
但我遇到在测试过程中有很多这种问题,因为有很多的条件下,一个全局变量的值可以重置(如讨论here)。
我怎么能存储的对象,以便其价值将可只要工作簿是开放的,在整个重复调用我的BeforeDoubleClick
事件?
使你的代码稳定,这将是最好的保证,让你'公共variable'值。顺便说一句,为什么'全球'而不是'公共'? –
存储它作为一个全球性的,但检查使用它,看它是否是'Nothing'之前:如果它不存在,然后使用'df.Create' –