문제

The following script executes a single rule against the inbox folder, but not sub-folders. How can I run it as if I checked the "include all sub-folders" check box when run manually?

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
도움이 되었습니까?

해결책

According to this page, there is an IncludeSubfolders parameter for the Rule.Execute method. So try:

rl.Execute ShowProgress:=True, IncludeSubFolders:=True
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top