Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

KMail has a really useful feature: you can define a series of rules which are only run when you press a keyboard shortcut, and then only on the highlighted messages. This allows me to read a message as it comes into the inbox, and then file it away with one key press.

How can I replicate this in Outlook? Possibly some VBA script triggered by a key press that runs all rules against all messages currently selected?

share|improve this question

4 Answers 4

How big is your folder? You can Run rules manually, but that applies to the whole folder, but I imagine that this could be really slow if your folder has a large number of messages.

That link describes using 'Manage Rules & Alerts' in the File tab to 'Run Rules Now'.

share|improve this answer

Unfortunately, there is no way to run Outlook rules on selected messages. Only on folders. :-( Even using Outlook Object Model in VBA.

share|improve this answer

You can help yourself with an auxiliary routine like this:

Public Sub TestMessageRule()
    '  Routine to test Mail Handlers MessageRule()'
    '  without incoming mail messages
    '  select an existing mail before executing this routine
    Dim objItem As Object
    Dim objMail As Outlook.mailItem
    Dim started As Long

    For Each objItem In Application.ActiveExplorer.Selection
        If TypeName(objItem) = "MailItem" Then
            Set objMail = objItem

                '  add the following declaration at the header:
                '  Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
                started = GetTickCount()
                MessageRule objMail

                ' showCheckerMail objMail.BillingInformation
                Debug.Print "elapsed " & (GetTickCount() - started) / 1000# & "s"
        End If
    Next
End Sub
share|improve this answer

The answer is No and Yes. No to messages, yes to messages you move to a folder.

The basic VBA used on many sites http://www.slipstick.com/outlook/rules/run-outlook-rules-startup/

Sub RunAllInboxRules()
    Dim st As Outlook.Store
    Dim myRules As Outlook.Rules
    Dim rl As Outlook.Rule
    Dim count As Integer
    Dim ruleList As String
    'On Error Resume Next

    ' get default store (where rules live)
    Set st = Application.Session.DefaultStore
    ' get rules
    Set myRules = st.GetRules

    ' iterate all the rules
    For Each rl In myRules
        ' determine if it's an Inbox rule
              If rl.RuleType = olRuleReceive And rl.IsLocalRule = True Then
            ' if so, run it
            rl.Execute ShowProgress:=True
            count = count + 1
            ruleList = ruleList & vbCrLf & rl.Name
        End If
    Next

    ' tell the user what you did
    ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
    MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"

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

If you want to run it against the folder you moved the message(s) to, rather than the Inbox, specify that folder.

http://msdn.microsoft.com/en-us/library/office/ff864433%28v=office.14%29.aspx

Say you create a folder under the Inbox named "RunRules"

Once you move the message(s) to the folder:

Set fldRunRules = st.GetDefaultFolder(olFolderInbox).Folders("RunRules")

rl.Execute Folder:=fldRunRules
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.