Pass vba Dictionary

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"


To avoid the error add the Microsoft Scripting Runtime (in Tools -> References).
Simplified example:

Sub test_dict()
    Dim dict As New Scripting.Dictionary
    Call process(dict)
End Sub

Sub process_dict(dict As Scripting.Dictionary)
    MsgBox dict.Count
End Sub

Tags:

Excel

Vba