Skip to content

Instantly share code, notes, and snippets.

@ken-itakura
Last active March 1, 2024 01:56
Show Gist options
  • Save ken-itakura/7bad50347732f298e3d3a0c7d017fa54 to your computer and use it in GitHub Desktop.
Save ken-itakura/7bad50347732f298e3d3a0c7d017fa54 to your computer and use it in GitHub Desktop.
Outlook VBA macro to execute all outlook sorting rules in multiple accounts.
Sub RunAllRules()
On Error Resume Next
Dim accounts As Outlook.accounts
Set accounts = Application.Session.accounts
Dim account As Outlook.account
rulesDone = ""
rulesError = ""
For Each account In accounts
rulesDone = rulesDone & account.DisplayName & "("
rulesError = rulesError & account.DisplayName & "("
Dim rules As Outlook.rules
Set rules = account.DeliveryStore.GetRules
Dim rule As Outlook.rule
For Each rule In rules
rule.Execute
If Err.Number <> 0 Then
rulesError = rulesError & rule.Name & "(" & Err.Number & "),"
'rulesError = rulesError & rule.Name & "(" & Err.Description & "),"
Else
rulesDone = rulesDone & rule.Name & ","
End If
Next rule
rulesDone = rulesDone & ")" & vbCrLf
rulesError = rulesError & ")" & vbCrLf
Next account
MsgBox rulesDone, vbOKOnly, "Completed rules"
MsgBox rulesError, vbOKOnly, "Error rules"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment