According to this page, there is an IncludeSubfolders
parameter for the Rule.Execute
method. So try:
rl.Execute ShowProgress:=True, IncludeSubFolders:=True
Question
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
Solution
According to this page, there is an IncludeSubfolders
parameter for the Rule.Execute
method. So try:
rl.Execute ShowProgress:=True, IncludeSubFolders:=True