在这种情况下,您可以使用
收藏 class
or
字典 class
Collection
类是built-in到 VBA 中,因此您无需添加外部引用即可使用它。你可以简单地声明它
Dim c as Collection
Set c = new Collection
Collection
暴露4个方法:add, count, item, remove
所以这对你来说可能还不够。
Customizing, expanding Collection class https://stackoverflow.com/questions/19373081/how-to-use-the-implements-in-excel-vba/19379641#19379641
如果你想使用类似的东西哈希表/哈希映射然后添加引用Microsoft Scripting Runtime
通过点击Tools
and References
在VBE窗口中
那么你可以使用早期绑定和智能感知Dictionary
class
Dim d as Dictionary
Set d = new Dictionary
或者使用后期绑定
Dim d as Object
set d = CreateObject("Scripting.Dictionary")
我会选择早期绑定(第一个示例 - 添加对 VBA 项目的引用),以便您可以使用 VBA Intellisense。
You can view Dictionary
or Collection
class using the Object Browser - simply hit F2 in the VBE window and type in Dictionary
or Collection
有用的阅读Dictionary class http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_3391-Using-the-Dictionary-Class-in-VBA.html