从嵌套字典中返回密钥excel vba

时间:2017-12-30 18:58:13

标签: excel vba dictionary nested

我有问题,嵌套字典的键返回到调用子函数。它返回运行时错误'424'对象必需

Set LoadCombinationDict = LCaseDict()
Set a = fs.CreateTextFile(file_name, True)

    For Each LCKey In LoadCombinationDict.Keys
        Line = LCKey
        For Each AddnlKey In AddnlCaseDict.Keys
            X = LoadCombinationDict(LCKey)(AddnlKey)
            Line = Line & ";" & X
        Next AddnlKey
        a.WriteLine (Line)
     Next LCKey
a.Close

以下是创建嵌套字典的功能

Function LCaseDict() as Scripting.Dictionary
'Some Code to create nested dictionary
End Function

如果我在子函数中包含上面的代码,那么字典工作正常。有没有办法将主列和嵌套字典的键返回到excel vba中的调用函数?

1 个答案:

答案 0 :(得分:1)

以下是如何迭代字典词典

Set LoadCombinationDict = LCaseDict()
Set a = fs.CreateTextFile(file_name, True)

    For Each LCKey In LoadCombinationDict.Keys
        For Each AddnlKey In LoadCombinationDict(LCKey).Keys
            X = LoadCombinationDict(LCKey)(AddnlKey)
            Line = Line & ";" & X
        Next AddnlKey
        a.WriteLine (Line)
     Next LCKey
a.Close