• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create a List of Rules

Slipstick Systems

› Outlook › Rules, Filters & Views › Create a List of Rules

Last reviewed on December 4, 2018     19 Comments

Applies to: Outlook (classic), Outlook 2007, Outlook 2010

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.

Sample Results

The VBA below creates the list of rules assigned to the default email account. If you are editing rules to test the macro, make sure you are working with the correct set of rules in Rules & Alerts.
Only the rules associated with the default account are listed

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:tips@outlook-tips.net
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:alias@gmail.com
8  Rule Name:DServices  Folder path:\\Personal Folders\test\t5  From:domain@mail.com
9  Rule Name:Test1  From:sally@smith.com
10  Rule Name:Test 2  From:steve@handyman.com
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

An alternative format for the text file is available in the macro here: ListRules - Block format. This code sample contains additional conditions and actions.

The results will be in this format:

1  Rule Name:This is a test
  Flagged:True
  Copy to:\\dianep@domain.com\Junk E-mail

2  Rule Name:Any
  Flagged:True
  Forward:True

ConditionsActions
olConditionAccount
olConditionAnyCategory
olConditionBody
olConditionBodyOrSubject
olConditionCategory
olConditionCc
olConditionDateRange
olConditionFlaggedForAction
olConditionFormName
olConditionFrom
olConditionFromAnyRssFeed
olConditionFromRssFeed
olConditionHasAttachment
olConditionImportance
olConditionLocalMachineOnly
olConditionMeetingInviteOrUpdate
olConditionMessageHeader
olConditionNotTo
olConditionOnlyToMe
olConditionOOF
olConditionOtherMachine
olConditionProperty
olConditionRecipientAddress
olConditionSenderAddress
olConditionSenderInAddressBook
olConditionSensitivity
olConditionSentTo
olConditionSizeRange
olConditionSubject
olConditionTo
olConditionToOrCc
olConditionUnknown
olRuleActionAssignToCategory
olRuleActionCcMessage
olRuleActionClearCategories
olRuleActionCopyToFolder
olRuleActionCustomAction
olRuleActionDefer
olRuleActionDelete
olRuleActionDeletePermanently
olRuleActionDesktopAlert
olRuleActionFlagClear
olRuleActionFlagColor
olRuleActionFlagForActionInDays
olRuleActionForward
olRuleActionForwardAsAttachment
olRuleActionImportance
olRuleActionMarkAsTask
olRuleActionMarkRead
olRuleActionMoveToFolder
olRuleActionNewItemAlert
olRuleActionNotifyDelivery
olRuleActionNotifyRead
olRuleActionPlaySound
olRuleActionPrint
olRuleActionRedirect
olRuleActionRunScript
olRuleActionSensitivity
olRuleActionServerReply
olRuleActionStartApplication
olRuleActionStop
olRuleActionTemplate
olRuleActionUnknown

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.

  1. Press ALT+F11 to open Outlook’s VB editor
  2. If asked, you need to enable Macros
  3. Expand Project1 and Microsoft Office Outlook Objects
  4. Double-click on ThisOutlookSession
  5. Copy the code and paste it into the VB editor window (right pane)
  6. Save the changes (Ctrl+S or click the Save icon)
  7. Press F8 or the Run button to run the macro

For more information, see How to use Outlook’s VBA Editor

 

Tools

Power Rules Manager

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

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.

More Information

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.)
OlRuleActionType Enumeration (Outlook)
Create a List of Rules was last modified: December 4th, 2018 by Diane Poremsky

Related Posts:

  • Use a macro to create a rule to move messages
  • Outlook's Rules and Alerts: Run a Script
  • Enable or Disable an Outlook Rule using Reminders
  • Server-side vs. Client-side Rules

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
19 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

serios
August 10, 2021 2:55 pm

You saved me a lot of programming time, thank you very much !!! and thank you very much for sharing the code!!!

1
0
Reply
Mike M
August 3, 2017 1:41 pm

Hi, I loved your code!

Can you tell me how I would add the list of emails that the email is being forwarded to?

Thanks much.

1
0
Reply
Steve
November 22, 2016 9:37 am

I had to uncomment the "On Error Resume Next" line in order to get rid of a "Type Mismatch" error I was getting running the macro in Outlook 2010. Not sure why the line would be in the macro, but commented out.

0
0
Reply
Marathon Oliver
November 6, 2014 12:55 am

It's been two years since this thread started. I've been experimenting with having VBA display properties associated with olRuleActionStartApplication. I can understand why Diane hasn't expanded her example from years ago. Programming in Outlook VBA can be challenging.

0
0
Reply
Diane Poremsky
Reply to  Marathon Oliver
November 6, 2014 11:35 pm

I like to sow a seed with some working code to show what is possible and point users in the right direction, so they can do more on their own. :)

0
0
Reply
Gasper
January 6, 2014 8:56 am

Hiya Diane,

thank you for this great website and the knowledge share.

I was trying to set an outlook task whereby an email with a specif text in the subject is 1. colour coded, 2. assigned to someone as a task for resolution within 24hrs, and 3. on the subject field a sequential identification number is assigned to the email.

The first two were easily managed but couldn't figure out how to get around the third criteria. Any help would be greatly appreciated.

Thank you and warm regards
Gasper

0
0
Reply
Diane Poremsky
Reply to  Gasper
January 7, 2014 1:18 am

The last one is tough because Outlook doesn't use wildcard or regex commands in filters. One possibility is a run a script macro that uses regex sets a category on all mail containing the id pattern.

0
0
Reply
Moshe
October 1, 2012 4:04 am

Hi, Diane.

I did everything you suggested but then I'm getting the following message:

Runtime Error: '-2147352567 (80020009)':
Could not complete the operation.
This store does not support rules.

I get this error on the very first line ("Sub ListRules()")

Can you help?

TIA
Moshe

1
0
Reply
Moshe
September 6, 2012 6:58 am

Hi, Diane.
I tried to embbed your code in my home Outlook (the only one I have without Exchange), but with no result.
Before inserting the VBA code, I made sure all macros were enabled, even for add-ins (through Outlook's options). I changed the location of the output file (the only change I made in the code, in all the places) but, when I tried to run your code, I got the "Macros are not enabled for this project ........" error.
After doing some digging around, I decided to create a self-certificate and sign my code.
I tried to run the code again (after restarting Outlook) but I got a "You don't have permission" error.
I tried it again, and I got a "File already opened" error.
Do you have any idea what's going on?

BTW, my configuration is Win7 + Office 2010 32bit.

TIA
Moshe

0
0
Reply
Diane Poremsky
Reply to  Moshe
September 7, 2012 5:27 am

As an FYI, while you are testing a macro, set macro security to low. It's easier than resigning the code. Once it's finished, then sign it.

The permission error is likely related to the file path line: C:\Rules\OLfilterlist.txt. You can use any folder & filename as long as you update the macro with the correct path. Try using your My Documents folder instead.

On the file opened error - the macro exited without closing the file as you tested it. Changing the filename in the macro is one way to get right of that error.

0
0
Reply
Starbuck
March 1, 2012 9:10 pm

The utility here describes something similar to what I've been using for years with Outlook 2003:
https://forums.slipstick.com/threads/86104-Inbound-email-filtering-beyond-Rules

I just upgraded to 2010 where I can't used CDO and prefer not to use Redemption, so I'm now re-writing this in C# as an add-in. I have a ton of VBA code which I'd be happy to share. Since I just wrote it for myself it's largely undocumented (and does rely on Redemption) so it probably won't do many people here any good - but VBA junkies would probably enjoy it. PM me if you have the required skills - it's not a plug-n-play solution by any stretch.

1
-1
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 34

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • Mail Templates in Outlook for Windows (and Web)
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Outlook Folders Appear Empty after Exporting an IMAP Account
  • Shared Mailboxes and the Default 'Send From' Account
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment