vba:从函数返回字典

这概述了我正在尝试做什么。

这不适合我,这是不清楚的。

提前感谢您的帮助。

Sub mySub() dim myDict as Dictionary myDict=new Dictionary myDict=myFunc() End Sub Function myFunc() dim myDict2 set myDict2 = new Dictionary 'some code that does things and adds to myDict2' myFunc=myDict2 End Function 

无论何时分配对象而不是值,都需要使用SET关键字:

  Sub mySub() dim myDict as Dictionary set myDict = myFunc() End Sub Function myFunc() as Dictionary dim myDict2 as Dictionary set myDict2 = new Dictionary 'some code that does things and adds to myDict2' set myFunc=myDict2 End Function 

你的原始代码也是创buildmyDict作为一个新的Dictionary对象,然后立即用另一个代替它。 你可以跳过这一步。