I'm having an issue with a global variable dropping out of scope. I have defined a public variable in "ThisWorkbook":
Public dict As Scripting.Dictionary
This gets initalized in "Workbook_Open()"
Set dict = New Scripting.Dictionary
After initialization I run a Sub (code located in "ThisWorkbook" still) that fills this dictionary with IDs and instances of a custom class.
I'm having trouble working with this dict variable in other modules though. The goal is to build a number of public functions that the worksheet will be able to call. These functions manipulate/retrieve/etc data in the custom classes in the dictionary.
For example, this test sub (code in ModuleXYZ) throws "Object variable or With block variable not set"
Private Sub TestSub()
Dim x As Integer
x = ThisWorkbook.dict.Count
End Sub
This is the same error I would get when I first started this coding project, when the dict fell out of scope in the "ThisWorkbook" module, and I'd have to redo the "Set dict = New Scripting.Dictionary"
My hope was that by setting the dict as a Public variable in "ThisWorkbook", that it would stay in scope the entire time this workbook was open.
Thanks - KC