I currently have my Outlook setup with Gmail. I have a couple of rules that I have defined which run on different folders (lables) in my account. I have filters already setup in GMail which will make emails skip the inbox and put them in the respective folders.

Whenever I get a new email, in those folders, my rules are not run (they are just for setting categories). I have to run them manually. I think its because the emails don't come to the inbox first but directly into the folder. Is there anyway to make outlook run rules automatically on those folders? A scheduled run should also be fine.


Here it is. Note this is specific to the Junk folder (olFolderJunk is an Outlook constant), and it will run any filter I create prefixed with "JUNK_FILTER_".

It is optimistic and has virtually no error checking, so use it at your peril. Don't use it if you don't understand it :)

Sub runRulesOnJunkFolder()
    Dim st As Outlook.Store
    Dim myRules As Outlook.Rules
    Dim rl As Outlook.Rule
    Dim count As Integer
    Dim ruleList As String
    Dim rulePrefix As String
    Dim ruleFolder As Long

    Dim outlookApp As Outlook.Application
    Dim objNS As NameSpace

    ruleFolder = olFolderJunk
    rulePrefix = "JUNK_FILTER_"

    Set objNS = Application.GetNamespace("MAPI")
    Set objJunkfolder = objNS.GetDefaultFolder(ruleFolder)

    ' 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 and rule name prefix matches
        If rl.RuleType = olRuleReceive And Left(rl.Name, Len(rulePrefix)) = rulePrefix Then

            ' if so, run it
            rl.Execute ShowProgress:=True, Folder:=objJunkfolder
            count = count + 1
            ruleList = ruleList & vbCrLf & rl.Name
        End If

    ' tell the user what you did
    ruleList = "These rules were executed against the folder: " & objJunkfolder.Name & vbCrLf & ruleList
    MsgBox ruleList, vbInformation, "Macro: runRulesOnJunkFolder"

    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
    Set objJunkfolder = Nothing
    Set objNS = Nothing
End Sub
| improve this answer | |

Categories do not work on IMAP accounts properly. Any categories assigned to Outlook objects in IMAP accounts will not sync with the server, so will only show up on that particular Outlook profile on that particular user account on that particular Windows installation. The only thing you can really use with IMAP and Outlook is standard on/off flags (not the different types that GMail or Exchange supports).

Categories are intended to be used with Exchange accounts, where they can be assigned with client-side rules and then sync with the server. They will also work fine with POP3 accounts, where the categories would be assigned and the emails sorted by client-side rules.

As categories can be assigned (with client-side rules) on emails that have already been sorted into folders on an Exchange server (using server-side rules), I would think that your rules are not working because categories are not really intended to be using on non-Exchange accounts.

I don't think that GMail can be used satisfactorily with any desktop email client, in my opinion, because of the unusual way the IMAP mailboxes are set up.

| improve this answer | |

One way to do this is to set up a recurring appointment which can fire a macro whenever the reminder pops up. The macro would run the filter. This seems a little cumbersome with lots of appointments in your calendar and it is unlikely to be fired when you want it to. I have not done this personally, but I am sure it is possible.

What I have done is make a macro that runs any filters which are named with a specific prefix on a specific folder. The macro picks the folder, the filters decide the action (in my case, 'delete'). It is adaptable by someone who knows VBA.

After I created the macro, I added a button on the outlook toolbar that runs it. I click the button whenever the mood strikes me.

I can post source code if you feel you can modify it to suit your needs.

| improve this answer | |
  • Can you post the code for the macro? Thanks! – tHeSiD Dec 29 '10 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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