【发布时间】:2015-04-02 00:06:21
【问题描述】:
我希望有一个 Dictionary dict 可用于工作表事件处理程序,因此我将其存储在模块 GlobalVariables 中,如下所示:
Public dict As Dictionary
dict 在Workbook_Open 事件中被初始化:
Private Sub workbook_open()
Set dict = New Dictionary
dict.Add "abc", "def"
End Sub
这是Sheet1中的事件处理程序:
Private Sub worksheet_beforedoubleclick(ByVal target As Range, cancel As Boolean)
If dict Is Nothing Then
Debug.Print "nothing"
Else
Debug.Print "not nothing"
End If
End Sub
当我第一次打开工作簿并双击Sheet1 中的一个单元格时,dict 不是Nothing。但是如果我在这一行设置断点:
If dict Is Nothing Then
然后在断点停止后结束子,然后我下次双击并到达相同的断点时,dict 是Nothing。似乎过早结束_beforedoubleclick 子会导致取消分配dict。我怎样才能防止这种情况发生?我想让这个公共变量在我调试时保持它的值。
【问题讨论】: