我正在VBA上的Workbook_Open()上建立公共词典。我想在我在电子表格中创建的任何模块中访问此词典中的项目。
我在ThisWorkbook
中的代码是:
Option Explicit
Public Dic As Scripting.Dictionary
Private Sub Workbook_Open()
Set Dic = New Scripting.Dictionary
Dic.Add Key:="cat", item:="Database"
Dic.Add Key:="pwd", item:="Password"
Dic.Add Key:="col", item:="Server"
End Sub
当我进入任何模块并使用msgbox
功能调用一个项目时,它不起作用:
MsgBox (Dic("col"))
任何提示,如何使这项工作?
想法是在电子表格的开头设置该词典,并在随后的任何模块中进行访问。
欢呼声