Valk Beekman wanted to share this VBA code sample that creates a text file containing a list of the rules used by the default email account. When the rule contains an email address, the address (or display name) is added to the output. It needs a little tweaking to list all the actions and conditions in a rule, but for those who just want a list of rules, in the order they are listed in Rules and Alerts, it works very well as is.
Note: when I tested this it would not work in my profile containing several Exchange accounts. It will work with POP3, and IMAP (at least in Outlook 2007/2010)
Note that this works with Outlook 2007 and up. It will not work with older versions of Outlook.
The resulting list is in this format:
1 Rule Name:Clear categories on mail (recommended) 2 Rule Name:Tips Folder path:\\Personal Folders\Inbox\test From:firstname.lastname@example.org 3 Rule Name:Clear categories on mail (recommended) 4 Rule Name:Autoaccept rule Subject:'Autoaccept rule' 5 Rule Name:Test Subject:'Test' 6 Rule Name:'?' or '?' or '?' or '?' Body Or Subject:'?' '?' '?' '?' 7 Rule Name:Test 3 From:email@example.com 8 Rule Name:DServices Folder path:\\Personal Folders\test\t5 From:firstname.lastname@example.org 9 Rule Name:Test1 From:email@example.com 10 Rule Name:Test 2 From:firstname.lastname@example.org 11 Rule Name:Follow up From:microsoft.com
Notes: The output does not support Unicode text as rule #5 looks for four Chinese characters (in the subject or body and deletes the message as spam).
VBA Macro to List Rules
This is not the most efficient code, but it works. I tested this VBA in Outlook 2007 with only an IMAP email account in the profile. It would not work in Outlook 2010 with an Exchange server account set as default (and several accounts in the profile). I'm not sure why yet but it works in Outlook 2010 with other profiles.
Sub ListRules() Dim colStores As Outlook.Stores Dim oFileSys As Object Dim oStore As Outlook.Store Dim oRoot As Outlook.Folder Dim oCondition As Outlook.RuleCondition Dim oCondfrom As Outlook.RuleCondition Dim oAction As Outlook.RuleAction Dim colRules As Object Dim oRule As Outlook.Rule Dim oInbox As Outlook.Folder Dim oMoveTarget As Outlook.Folder Dim sOutput As String Dim myVar As Variant 'On Error Resume Next Set oFileSys = CreateObject("Scripting.FileSystemObject") 'Create a folder named Rules on your C drive or change the path to use an existing folder If oFileSys.FileExists("C:\Rules\OLfilterlist.txt") Then oFileSys.DeleteFile ("C:\Rules\OLfilterlist.txt") End If Open "C:\Rules\OLfilterlist.txt" For Output As #1 Set colStores = Application.Session.Stores Set oStore = colStores(1) Set oRoot = oStore.GetRootFolder Set colRules = oStore.GetRules For Each oRule In colRules sOutput = (oRule.ExecutionOrder) & Chr(9) & "Rule Name:" & (oRule.Name) For Each oAction In oRule.Actions If oAction.Enabled = True Then If oAction.ActionType = olRuleActionMoveToFolder Then sOutput = sOutput & Chr(9) & "Folder path:" & (oAction.Folder.FolderPath) End If 'add more actions here End If Next For Each oCondition In oRule.Conditions If oCondition.Enabled = True Then If oCondition.ConditionType = olConditionFrom Then sOutput = sOutput & Chr(9) & "From:" & (oRule.Conditions.From.Recipients(1)) End If 'add more conditions here End If Next Print #1, sOutput Next Close #1 End Sub
Adding More Conditions and Actions
The basic macro was written for a specific purpose - to get the From conditions and the folder used in the Move to folder action. Adding more conditions and actions is very easy, although it does require a little knowledge of how to use the VBA Editor.
Below is a sample of the VBA needed to get the Subject, Body, and message header rules. The remaining conditions and actions will use similar code.
To use these with the code above, paste them where the 'add more conditions here' line is.
'Words in the Subject If oCondition.ConditionType = olConditionSubject Then 'use this format when the condition may contain multiple values sOutput = sOutput & Chr(9) & "Subject:" For Each myVar In oRule.Conditions.Subject.Text sOutput = sOutput & "'" & myVar & "' " Next End If 'Words in the body If oCondition.ConditionType = olConditionBody Then sOutput = sOutput & Chr(9) & "Body:" & (oRule.Conditions.Body.Text) End If 'Message header contains If oCondition.ConditionType = olConditionMessageHeader Then sOutput = sOutput & Chr(9) & "Header:" & (oRule.Conditions.MessageHeader.Text) End If 'body or subject If oCondition.ConditionType = olConditionBodyOrSubject Then sOutput = sOutput & Chr(9) & "Body Or Subject:" For Each myVar In oRule.Conditions.BodyOrSubject.Text sOutput = sOutput & "'" & myVar & "' " Next End If
The results will be in this format:
1 Rule Name:This is a test Flagged:True Copy to:\\email@example.com\Junk E-mail 2 Rule Name:Any Flagged:True Forward:True
Using the VBA Editor
Copy and paste the VB code into Outlook's VB Editor. You'll also need to allow macros to run. If you aren't asked if you want to allow macros when you open the VB editor, you'll need to change the macro security in Options, Trust Center to 'Always ask' about macros. We do not recommend the lowest security setting to never ask about macros.
When you paste the code, the text colors should be the same as seen in the code above. Red lines mean there is an error in the code.
- Press ALT+F11 to open Outlook’s VB editor
- If asked, you need to enable Macros
- Expand Project1 and Microsoft Office Outlook Objects
- Double-click on ThisOutlookSession
- Copy the code and paste it into the VB editor window (right pane)
- Save the changes (Ctrl+S or click the Save icon)
- Press F8 or the Run button to run the macro
For more information, see How to use Outlook’s VBA Editor
Sperry Software's Power Rules Manager, an add-in that allows you to view and edit your rules from a grid window, received a small but significant upgrade: You can now drag and drop Outlook rules right in the grid window for simple control over Outlook rule execution order. And, if you hold down the Shift key while the grid is scrolling as you drag your rules, it goes into "turbo mode" in case you have hundreds (or even thousands) of rules. It also now has several other nice enhancements including support for non-default sets of rules.
Timed Email Organizer is a brand new add-in which can replace or augment your Outlook rules. Unlike Outlook, this add-in will act on emails based on how old they are, supports ANDs, ORs, NOTs and wildcards in the conditions, and has a test mode so that you can see what the effect of a given rule would be if it were run. It will even import your current Outlook rules and automatically disable them for you.