2

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?

5 Answers 5

1

Yes you can do this, but you have to be a little tricky. The steps overview : make filing rules that look for a category, then make a button run a macro to change the messages selected to that category and then run the rules. See the full answer on this question, including the macro code...

Quickly running Outlook rules on demand?

I made my answer there a little more involved by naming the rules based on category with a prefix so they can be run specifically by the macro, but this is somewhat optional.

0

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'.

0

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

0

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
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .