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.
At this point, I've confirmed it works in Outlook 2007 with only an IMAP email account in the profile and in Outlook 2010 with only a Hotmail Connector account in the profile. It would not work in my Outlook 2010 profile containing several Exchange accounts.
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
InboxRULES engine is an add-in for MS Outlook for processing incoming and outgoing messages. It calls Ornic actions after message arrives or is sent if the defined conditions is matched.
InboxRULES for Outlook ("InboxRULES CE") is an add-in for MS Outlook for processing incoming and outgoing messages. The message is processed when it arrives to MS Outlook or after it is sent. If the message matches defined restrictions (Boolean expression support) InboxRULES CE calls our actions. InboxRULES for Outlook is a client side engine which requires MS Outlook to run to process messages. Now supports Outlook 2013 and Windows 8.
Do you feel limited by the Outlook rules wizard? The Power Rules Manager add-in for Microsoft Outlook simplifies managing your Outlook rules. Your rules will be shown in a clear and simple grid, that can be sorted by simply clicking on any of the grid headers. Print your rules. Save your rules to a plain text file (TXT), a comma delimited file (CSV), or Microsoft Excel (XLS) formats. Works with Microsoft Exchange Server but doesn't require it. Works with Microsoft Outlook 2010 (64-bit and 32-bit) and Outlook 2007. (Note: does not work with Outlook 2003 or below.)
Another macro that can be useful when troubleshooting rules is Finding Rules Related to a Folder in Outlook. This macro, written by Outlook Developer MVP David Lee, adds the ability to right-click on a folder and see all of the rules associated with the selected folder. (Outlook 2007 and later.)