I was asked how a user could manually run all or a single rule, without having to use the outlook rules dialog box. here is how you do it.
First, go into the VB Editor, Tools -> Macro’s > Visual Basic Editor (or press ALT-F11)
assuming you dont already have any modules in here. Press Insert -> Module
you will be presented with a new window waiting for code, paste this in for all rules:
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 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
______________________________________________________________________________________________________________________________
and this for a single rule, dont forget to change rulename
___________________________________________________________________________________________________________________________________
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim runrule As String
dim rulename as string
Rulename = "*****name of rule*****"
Set st = Application.Session.DefaultStore
Set myRules = st.GetRules
For Each rl In myRules
If rl.RuleType = olRuleReceive Then
If rl.Name = rulename Then
rl.Execute ShowProgress:=True
runrule = rl.Name
End If
End If
Next
ruleList = "This rule was executed against the Inbox:" & vbCrLf & runrule
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
NB: if it doesnt work at first, as per this comment you may want to try replacing the “s with your own. It’s possible they are lost in translation.
This will create a new macro that runs all the rules one by one in against your inbox.
Now create a button, goto View -> Tool bars -> Customize
go into the Toolbas Tab, and click New, call it what you want. I called mine “Rules”
The toolbar will be created floating, you can drag this now where you want it in the client. or leave it alone for now.
then go into the Commands Tab, scroll down to Macro’s on the left hand side, you should see Project1.Runallinboxrules in there. drag that up to the new toolbar and release it. This will make a new icon to the macro.
you can right click the icon to customise it. To bring it inline with the rest of the toolbars, I set mine to ‘Default Style’
Then you can close the Toolbar config window. and test it out. it will tell you which rules were run when it finishes


#1 by deyvsh on September 2, 2010 - 8:45 am
Just what I was looking for, thanks!
#2 by cg on September 22, 2010 - 6:11 pm
the single rule name macro doesn’t work..
the all rules macro does..
really trying to find the single one for one specific rule
#3 by pyrocam on September 22, 2010 - 7:49 pm
Hi There, this definately does work, if you are having issues you could try replacing the line
If rl.Name = rulename Then
with
If rl.Name = “your rule name” Then
#4 by Anthony on September 29, 2010 - 2:05 pm
The single one didn’t work at first for me. Then I noticed the quotes were funny looking from the code I copied. Try deleting the quotes then replacing them by typing them in. They must have copied over incorrectly but changing them worked for me. Thanks for the code it works great!
#5 by pyrocam on September 29, 2010 - 7:09 pm
Good call, the formatting is probably giving you curly quotation marks eg: ˮ instead of ". I will see what I can do to fix it. Cheers
-edit:done, escaped all “‘s to "
#6 by John on January 13, 2011 - 6:12 pm
I am getting a debug on this line…
Set myRules = st.GetRules
Is there a particular reference that needs to be checked in the Tools | References… menu?
#7 by pyrocam on January 13, 2011 - 9:28 pm
No references required.
have you got some rules setup? what version of office are you using? what is the error message?
#8 by John on January 14, 2011 - 12:26 am
Windows 7, Outlook 2010
Run-time error ‘-2147352567 (80020009)’:
This store does not support rules. Could not complete the operation.
#9 by pyrocam on January 14, 2011 - 1:43 am
sounds like it cant logon to the store properly, are you running it from within outlook, or an external script?
you could try starting outlook in safe mode (start , run, ‘outlook.exe /safe’ ) and running it, to see if its an addon thats causing the issue.
#10 by spanijel on February 8, 2011 - 10:55 pm
GREAT !!! this is exactly the shortcut that I was looking for.
Thanks.
How can I apply this macro to execute on a pst file (let’s say mySpecificeMails.pst) instead of inbox folder?
#11 by Wayland Moncrief on February 18, 2011 - 6:51 pm
I get compile errors when running the rules macro: user defined type not allowed. Are there files I need to include and how do I include them?
#12 by pyrocam on February 18, 2011 - 9:40 pm
There are no files or references required, what line is highlighted when it gives the error?
#13 by Nila on February 19, 2011 - 11:36 pm
The all rules one worked for me after I changed the ‘ but it only runs rules from my Exchange account, not the account I am in or all accounts.
#14 by Nila on February 22, 2011 - 6:06 pm
To clarify, I’m connected to Exchange and 2 IMAP accounts. The run all rules script runs the exchange rules but not the IMAP account, regardless of which account folder I’m in. Using Win 7 Pro 64, Office 2010.
#15 by Sumit on March 22, 2011 - 8:57 pm
Awesomeeeeeeeeeeeee. thanks works like a charmmmmmmmm. Note type in the quotes cause when you copy paste the quotes change.
#16 by Sumit on March 23, 2011 - 1:14 pm
Ok got an issue. It just ran once and stopped working.
#17 by Kevin on December 1, 2011 - 7:22 pm
Very useful, thank you!
#18 by Angel on December 2, 2011 - 6:45 pm
Got the same error as John…
Windows 7, Outlook 2010
Run-time error ‘-2147352567 (80020009)’:
This store does not support rules. Could not complete the operation.
The debuger highlights the following line:
Set myRules = st.GetRules
#19 by Charlie on December 19, 2011 - 12:27 pm
I also had the same problem as john. When I tried to run in safe mode no macros could be run.
#20 by Richard on December 19, 2011 - 8:54 pm
Same 0×80020009 error here on an IMAP setup – looks like the default store is “Personal Folders” which is the .pst Outlook created, instead of “Account@EmailProvider.com” which is the IMAP default store. I’ve not yet been able to get the macro to point to the IMAP store though
#21 by Rob on December 29, 2011 - 12:06 pm
Hi, Got a question trying to use your script to disable only one rule. But this isn;t working, I’m complete new to this, so hope you can help. Underneath is hat I tried. Thanks in advance.
Rob
———-
If rl.Name = rulename Then
rl.Enabled = False
‘rl.Execute ShowProgress:=True
‘runrule = rl.Name
End If
#22 by David on January 19, 2012 - 7:11 pm
Is it possible to designate more than one (but not all) rules with this method? I’m a non-coder, but i follow instructions REAL well.
#23 by Michael on January 20, 2012 - 2:46 pm
Any solution for the 0×90020009 error with an IMAP setup? Outlook 2010 can sync with a gmail account, but neither the All Rules or Single Rule macros will run. They both work fine when I use them on my work account since that uses Exchange Server.
#24 by Elli on January 30, 2012 - 9:38 pm
It’s working perfectly! However, I’d like to run this only on “Read” messages. Any ideas? Thank you!
#25 by DJH on February 13, 2012 - 9:10 am
The above macro template proved very helpful for Outlook 2007 rules management (my 385+ rules are manually run at least once daily) – thanks !!
Note 1: Using trial-n-error (I’m a macros novice), I made minor revisions to add “Ready” and “Done” message boxes (see revised template below).
Note 2: To enable this macro, the Outlook 2007 Macro Security Setting may need to be switched to the following option: Tools >> Macros >> Security >> “Warnings for all macros”.
==========
Sub A_Run_All_Inbox_Rules()
‘ Macro Ready Message Box
MsgBox “Ready: All Inbox Rules will be executed.”
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 Then
‘ if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
‘ Macro Done Message Box
MsgBox “Done: All Inbox Rules have been executed.”
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
==========
#26 by Norm on February 16, 2012 - 4:34 pm
Worked like a charm. To the guy in the comment above me, you have your execution of the rule commented out! ‘ turns the line into a comment and it doesn’t execute
#27 by Christopher Adams on February 22, 2012 - 8:48 pm
I put the e-mails I have answered into a DONE subfolder and then use my rules on the DONE folder.
Is there any way this code can be adapted sot hat all of my rules in the Rules Wizard run on the subfolder and not the Inbox?
#28 by D.J. Clark on March 26, 2012 - 2:26 pm
Hello – I’d like to use this process to archive my sent e-mail items. I have a rule that does this, but when I create the VB routine and button as above, it does not archive the sent e-mails. I don’t get an error, but it doesn’t work. Is the routine above someone specific to to Inbox (as opposed to the Sent folder)? Thanks
#29 by Danehbear on April 16, 2012 - 5:25 pm
Thanks!
#30 by Bill Hendricks on May 4, 2012 - 8:33 pm
Ditto on #28′s question. Can this macro be modifed to run ALL rules rather than just INBOX rules? I tried modifying the inbox condition:
‘ iterate all the rules
For Each rl In myRules
‘ determine if it’s an Inbox rule
‘If rl.RuleType = olRuleReceive Then
‘ if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
‘End If
Next
… but it still doesn’t work on SENT rules.