vba - 运行时错误 '13' : Type Mismatch, 从字典访问值时

标签 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'.

谁能告诉我为什么会出现这样的错误以及我如何获得值(value)。

最佳答案

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

关于vba - 运行时错误 '13' : Type Mismatch, 从字典访问值时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20758494/

相关文章:

vba - 宏 - 每隔一行复制并粘贴单元格

vba - 如何使用 VBA 代码选择/打开多页(用户窗体)下可用的页面

Excel VBA 检查 InStr 函数中的值

vba - 括号不被识别

c# - CSV 编码问题 (Microsoft Excel)

excel - 每 n 行自动填充

excel - 使用 excel 或在 excel 中求平均值

c# - 后台 Excel 线程未被杀死 C#

excel - 来自另一张纸的 ListFillRange

excel - 仅使用一些数组元素执行 for 循环