How do I pass a dictionary object to another function? The code below:
Sub aaa(dict As Object)
Set dict = CreateObject("Scripting.Dictionary")
...
process dict
End Sub
Sub process(dict As Scripting.Dictionary)
MsgBox dict.Count
End Sub
gives the compile error "User defined type not defined".
Also,
Set dict = CreateObject("Scripting.Dictionary")
works, but
Dim dict As New Scripting.Dictionary
gives "User defined type not defined".
I’m using Excel 2010.
When you use
CreateObjectyou are binding the object at run-time (ie, late binding). When you useAs Scripting.Dictionarythe object is bound at compile-time (ie, early binding).If you want to do early binding you will need to set a reference to the correct library. To do this, go to Tools –> References… and select “Microsoft Scripting Runtime”