VBA Word: Store and retrieve info in a collection
Posted on 2013-11-30
I am using Word VBA and want to store some data in a Collection using two arguments: a Key and some data associated with that key. Here is the code:
' Test storing and retrieving some data.
Dim ACollection As New Collection
Dim KeyData As Variant
Dim ItemData As Variant
' Make up some data: a key and something related to that key
KeyData = "5"
ItemData = "Test"
ACollection.Add Key:=KeyData, Item:=ItemData 'Add items to the collection
' Now try to retrieve that information
Dim MyObject As Variant
For Each MyObject In ACollection
ItemData = MyObject ' half of the information stored is retrieved
Key Data = ?? ' how do I get the Key used in storing the information?
Of course my actual code is a bit more complex. The above just shows the essence of the problem: to retrieve both the data stored and the key used for storing it.
Thanks for any help
JRA in Priddis, Alberta