Run Rules Now

Rules can be run manually, however, that requires lots of clicks. Use this script to run all rules with your preferred settings.

Last modified: 2015/05/07 | Accessed: 39.175  | #146
◀ Previous sample Next sample ▶
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.

Determine your preferred settings in the following first function.

  • RunEnabledRules: True means all enabled rules should be executed. Set it to False to ignore all enabled rules.
  • RunDisabledRules: False means all disabled rules should be ignored. Set it to True if you want to execute all disabled rules.
  • ExecuteOption: The values of 0, 1 or 2 set whether to run the rules on all messages, on the read messages only, or on the unread ones only.
  • Inbox: True means the rules should be executed for the inbox (and maybe its subfolder, too). Set the value to False to make the current folder instead to the start folder.
  • IncludeSubfolders: True means the rules should be executed for the start folder and all its subfolders. Set it to False if you want to run the rules only for the start folder.

Start the macro, for instance, by pressing ALT+F8.

tip  How to add macros to Outlook
Public Sub RunRules()
  Dim RunEnabledRules As Boolean
  Dim RunDisabledRules As Boolean
  Dim ExecuteOption As Long
  Dim IncludeSubfolders As Boolean
  Dim Inbox As Boolean
  'Execute the enabled rules (true/false)
  RunEnabledRules = True
  'Execute the disabled rules (true/false)
  RunDisabledRules = False
  'For which messages do you want to run the rules?
  '0 = all messages
  '1 = read messages only
  '2 = unread messages only
  ExecuteOption = 0
  'Start with the Inbox (true) or with the current folder (false)
  Inbox = True
  'Execute the rules only for the start folder (false) or also for its subfolders (true)
  IncludeSubfolders = False
  RunRules_ex RunEnabledRules, RunDisabledRules, ExecuteOption, IncludeSubfolders, Inbox
End Sub
OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.

The following part does the job of running the rules. Here you don't need to edit anything.

Private Sub RunRules_ex(ByVal RunEnabledRules As Boolean, ByVal RunDisabledRules As Boolean, _
  ByVal ExecuteOption As Long, ByVal IncludeSubfolders As Boolean, ByVal Inbox As Boolean)
  Dim Store As Outlook.Store
  Dim Rules As Outlook.Rules
  Dim Rule As Outlook.Rule
  Dim Folder As Outlook.Folder
  If Inbox Then
    Set Folder = Application.Session.GetDefaultFolder(olFolderInbox)
    Set Folder = Application.ActiveExplorer.CurrentFolder
  End If
  Set Store = Application.Session.DefaultStore
  Set Rules = Store.GetRules
  For Each Rule In Rules
    If Rule.RuleType = olRuleReceive Then
      If Rule.Enabled Then
        If RunEnabledRules Then
          Rule.Execute , Folder, IncludeSubfolders, ExecuteOption
        End If
        If RunDisabledRules Then
          Rule.Execute , Folder, IncludeSubfolders, ExecuteOption
        End If
      End If
    End If
End Sub
ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.
email  Send a message