运行时错误'13':类型不匹配,从字典访问值

时间:2013-12-24 09:43:45

标签: vba excel-vba excel

我为键值对列表创建了一个字典。其中key应为string,Value部分应为arrayList。当我在字典中添加键和值时,它工作正常,但当我尝试将值作为arrayList时,它给出运行时错误'13'

   Dim myValue As Dictionary
   Dim inrArrLstVal As Object
   Dim arrLstStor as Object

   Set myValue = New Dictionary
   Set arrLstStor = CreateObject("System.Collections.ArrayList")
   Set inrArrLstVal = CreateObject("System.Collections.ArrayList")

   myValue.Add searchpart, inrArrLstVal   ''' searchpart is string
   arrLstStor = myValue .Items(searchpart) ''' This gives type Mismatch Error '13'.

任何人都可以告诉我为什么会出现这样的错误,我怎样才能获得价值。

1 个答案:

答案 0 :(得分:2)

Sub testarrlst()

    Dim dc As Scripting.Dictionary
    Dim inrArrLstVal As Object
    Dim arrLstStor As Object

    Set dc = New Scripting.Dictionary
    Set inrArrLstVal = CreateObject("System.Collections.ArrayList")

    dc.Add "test", inrArrLstVal
    Set arrLstStor = dc.Item("test")

    Debug.Print TypeName(arrLstStor)

End Sub