Enumerate a Dictionary Object

Although the Dictionary object does not have an enumerator, it does have an Items method that returns a Variant array. You can use the For…Each construct on the array:

 Dim vItem As VariantDim dict As Scripting.DictionarySet dict = New Scripting.Dictionarydict.Add "Item1", "Item data 1"dict.Add "Item2", "Item data 2"dict.Add "Item3", "Item data 3"For Each vItem In dict.Items	Debug.Print vItemNextSet dict = Nothing

Before you can use the Dictionary object in your application, you must set a Project Reference to the Microsoft Scripting Runtime (scrrun.dll).

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: