Does VBA have Dictionary Structure?

fessGUID picture fessGUID · May 27, 2009 · Viewed 297.6k times · Source

Does VBA have dictionary structure? Like key<>value array?

Answer

Mitch Wheat picture Mitch Wheat · May 27, 2009

Yes.

Set a reference to MS Scripting runtime ('Microsoft Scripting Runtime'). As per @regjo's comment, go to Tools->References and tick the box for 'Microsoft Scripting Runtime'.

References Window

Create a dictionary instance using the code below:

Set dict = CreateObject("Scripting.Dictionary")

or

Dim dict As New Scripting.Dictionary 

Example of use:

If Not dict.Exists(key) Then 
    dict.Add key, value
End If 

Don't forget to set the dictionary to Nothing when you have finished using it.

Set dict = Nothing