我有以下代码:
Function MC() As Object()
Dim RulesList(0 To 10) As Object
Dim Rule
Set Rule = CreateObject("Scripting.Dictionary")
Rule.Add "Sender", "Test"
Rule.Add "Subject", "bbb"
Rule.Add "Folder", "ccc"
Rule.Add "MarkRead", False
Set RulesList(0) = Rule
Set Rule = CreateObject("Scripting.Dictionary")
Rule.Add "Sender", "Java"
Rule.Add "Subject", "bbb"
Rule.Add "Folder", "ccc"
Rule.Add "MarkRead", False
Set RulesList(1) = Rule
Set MC = RulesList
End Function
在Outlook VBA中。 代码抛出
“编译错误:无法在线分配给阵列设置MC = RulesList
请问有人在这帮助我吗?我想创建一个字典对象数组并返回它们。
EDIT:在函数签名结束时删除()并使用MC = RulesList代替Set MC = RulesList,但是,我不能在我的调用函数中分配这个,有人能指点我帮忙吗?
答案 0 :(得分:0)
一些注意事项:
Function MC() As Object()
Dim RulesList(0 To 10) As Object
Set Rule = CreateObject("Scripting.Dictionary")
Rule.Add "Sender", "Test"
Rule.Add "Subject", "bbb"
Rule.Add "Folder", "ccc"
Rule.Add "MarkRead", False
Set RulesList(0) = Rule
Set Rule = CreateObject("Scripting.Dictionary")
Rule.Add "Sender", "Java"
Rule.Add "Subject", "bbb"
Rule.Add "Folder", "ccc"
Rule.Add "MarkRead", False
Debug.Print Rule(1)
Set RulesList(1) = Rule
MC = RulesList
End Function
Sub getmc()
Dim abc
abc = MC
Set Rule = abc(1)
a = Rule.items
Debug.Print a(0)
End Sub