如何对Outlook收件箱中的所有子文件夹执行以下脚本?

时间:2014-03-21 21:43:38

标签: vba exchange-server outlook-vba

以下脚本针对收件箱文件夹执行单个规则,但不执行子文件夹。如何运行它,就像我检查了"包括所有子文件夹"手动运行时复选框?

Sub RunAllInboxRules()
    Dim st As Outlook.Store
    Dim myRules As Outlook.Rules
    Dim rl As Outlook.Rule
    Dim runrule As String
    Dim rulename As String

    rulename = "MarkNonEmployeeMailAsRead"

    Set st = Application.Session.DefaultStore
    Set myRules = st.GetRules

    For Each rl In myRules
        If rl.RuleType = olRuleReceive Then
            If rl.Name = rulename Then
                rl.Execute ShowProgress:=True
                runrule = rl.Name
            End If
        End If
    Next

    ruleList = "This rule was executed against the Inbox:" & vbCrLf & runrule
    MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"

    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

根据this pageIncludeSubfolders方法有一个Rule.Execute参数。所以试试:

rl.Execute ShowProgress:=True, IncludeSubFolders:=True