0

我有以下代码:

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 中。代码抛出

“编译错误:无法在 Set MC = RulesList 线上分配给数组

有人可以帮我吗?我想创建一个字典对象数组并返回它们。

EDIT: Removing () at the end of function signature and using MC = RulesList in place of Set MC = RulesList works, however, I can't assign this in my calling function anymore, can anyone point me to help on that?

4

1 回答 1

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
于 2013-02-02T12:52:13.813 回答