引用Microsoft Scription Runtime
声明Dim d As New Scripting.Dictionary
看楼主选的答案,看来楼主VBA刚入门, Scripting.Dictionary是需要引用Microsoft Scription Runtime.dll的,否则获取的对象是nothing。而且Dictionary是键值对,你的用法也错了,正确的用法是
d.add key,value 增加键值对
d.item(key) 获取键对应的值
....
VBA找那个Dictionary,与C#,JAVA,OC等语言的Dictionary有点区别,就是VBA中Dictionary是有序的,其他语言中Dictionary是散列的。
VBA里就没有Dictionary这种变量类型……没加载前只能先定义为对象,即Object
Dim d As As Object
Set d = CreateObject("Scripting.Dictionary")
dim d as object
set d = createobject("scripting.dictionary")
dictionary是你的自定义类型