New to vba. How to pass dictionary object to another function.
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 a 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 use excel 2010
When you use CreateObject
you are binding the object at run-time (ie, late binding). When you use As Scripting.Dictionary
the 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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With