How to read a collection name index value?
Hi George,
Kind of depends on what you mean by a collection and if items in the
collection have a name property. Eg with sheets you could do this -
Set objShts = ActiveWorkbook.Worksheets
sName = objShts(objShts(1).Name).Name
idx = objShts(sName).Index
If your collection is declared "As Collection", there is no direct way to
return a 'Key' from an item's index. However there's an API approach that
can return an array of all the Key's in a collection.
Regards,
Peter T
"G Lykos" wrote in message
...
Greetings!
You can use a collection index value, for example Gizmos(13).Name, to get
the name of item 13. Am wondering if there is an equivalent direct
mechanism to use a collection item name to get its index value, along the
lines of Gizmos("SomeName").Index. If symmetrical functions (properties,
I
guess, in VBA speak) existed, Gizmos(Gizmos("SomeName").Index).Name would
return "SomeName" - an identity property of sorts.
I suppose a brute-force approach would be to create a function doing a For
name/string comparison loop over 1 to Gizmos.count. Am hoping for
something
more direct.
Thanks,
George
|