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