1
我想有可用到工作表的事件处理程序字典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
Wh我首先打开工作簿,然后双击Sheet1
中的单元格,dict
不是Nothing
。但是,如果我把一个断点在这条线:
If dict Is Nothing Then
,然后结束分了暂停在断点处后,那么下一次我双击并达到相同的断点,dict
是Nothing
。看起来过早结束_beforedoubleclick
子具有取消分配dict
的效果。我怎样才能防止这种情况发生?我想在调试时让这个公共变量保持其值。