问题
I was about to ask a question when the solution came in one test. So I'm posting anyway and answering, so others can benefit.
The question was:
I run the code below and get a runtime error 450 - Wrong number of arguments or invalid property assignment
Dim data, tmpDict As Dictionary
Set data = New Dictionary
Set tmpDict = New Dictionary
data.Add 123, tmpDict
Set tmpDict = data.Item(123)
tmpDict.Add "somekey", 100
data.Item(123) = tmpDict
The error occur in last line. The code was simplified to focus on changing a nested dictionary in an already existing item.
How can I succeed in this?
回答1:
The solution can be achieved contracting the last 3 lines in just 1, using:
data.Item(123).Add "somekey", 100
instead of:
Set tmpDict = data.Item(123)
tmpDict.Add "somekey", 100
data.Item(123) = tmpDict
来源:https://stackoverflow.com/questions/29659656/changing-nested-dictionary-in-vba