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

问题描述 投票:0回答:1

我有问题,嵌套字典的键返回到调用子函数。它返回运行时错误'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中的调用函数?

excel vba dictionary nested
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.