I'm trying to declare a public dictionary variable that will survive as long as the workbook is open. At the moment I'm using at the top of one of my modules:
Public dict As Scripting.Dictionary
I can access it from multiple subs within the same module, but as soon as all the code finishes running it goes out of scope. I've tried declaring it in the Workbook_Open() sub, but that doesn't seem to survive either.
The reason I'm doing this: I'm loading in a lot of external XML information that I will need to dynamically access while the sheet is open quickly (so I don't want to reload the xml each time). Instead I'd rather load the XML at the beginning, sort the relevant information into instances of custom classes that do the work I need.
Any suggestions?
Thanks
EDIT:
I've added the code as per the suggestion below, but the dictionary still seems to go out of scope as soon as the code finishes running. When other subs try to access it, I get an "Object Required" error
Option Explicit
Public dict As Scripting.Dictionary
Private Sub Workbook_Open()
Set dict = New Scripting.Dictionary
dict.Add "ID", New cItemClass
End Sub