How to run Outlook 2007/2010/2013/2016 Rules from a button

(update 2016-06-08 This has been tested with Outlook 2016 and seems to work!)

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.


VB Editor in MS Outlook 2007This 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 Toolbars 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 customize 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

macro setup in outlook 2007

Note: This article uses code that was probably taken from this page http://www.outlookcode.com/codedetail.aspx?id=1266

UPDATE 2016 version

I have tested this as is on outlook 2016 and it worked AS IS. 🙂

88 thoughts on “How to run Outlook 2007/2010/2013/2016 Rules from a button

  1. deyvsh September 2, 2010 at 8:45 am

    Just what I was looking for, thanks!

  2. cg September 22, 2010 at 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

    • pyrocam September 22, 2010 at 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

  3. Anthony September 29, 2010 at 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!

    • pyrocam September 29, 2010 at 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 "

  4. John January 13, 2011 at 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?

    • pyrocam January 13, 2011 at 9:28 pm

      No references required.
      have you got some rules setup? what version of office are you using? what is the error message?

    • Pedro November 20, 2015 at 3:44 pm

      Hi John! I worked out the problem by setting my Macros security level to low.

  5. John January 14, 2011 at 12:26 am

    Windows 7, Outlook 2010

    Run-time error ‘-2147352567 (80020009)’:
    This store does not support rules. Could not complete the operation.

    • pyrocam January 14, 2011 at 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.

  6. spanijel February 8, 2011 at 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?

  7. Wayland Moncrief February 18, 2011 at 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?

    • pyrocam February 18, 2011 at 9:40 pm

      There are no files or references required, what line is highlighted when it gives the error?

  8. Nila February 19, 2011 at 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.

  9. Nila February 22, 2011 at 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.

  10. Sumit March 22, 2011 at 8:57 pm

    Awesomeeeeeeeeeeeee. thanks works like a charmmmmmmmm. Note type in the quotes cause when you copy paste the quotes change.

  11. Sumit March 23, 2011 at 1:14 pm

    Ok got an issue. It just ran once and stopped working.

  12. Kevin December 1, 2011 at 7:22 pm

    Very useful, thank you!

  13. Angel December 2, 2011 at 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

  14. Charlie December 19, 2011 at 12:27 pm

    I also had the same problem as john. When I tried to run in safe mode no macros could be run.

  15. Richard December 19, 2011 at 8:54 pm

    Same 0x80020009 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 🙁

  16. Rob December 29, 2011 at 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

  17. David January 19, 2012 at 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.

  18. Michael January 20, 2012 at 2:46 pm

    Any solution for the 0x90020009 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.

  19. Elli January 30, 2012 at 9:38 pm

    It’s working perfectly! However, I’d like to run this only on “Read” messages. Any ideas? Thank you!

  20. DJH February 13, 2012 at 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

    ==========

  21. Norm February 16, 2012 at 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 😉

  22. Christopher Adams February 22, 2012 at 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?

  23. D.J. Clark March 26, 2012 at 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

  24. Danehbear April 16, 2012 at 5:25 pm

    Thanks!

  25. Bill Hendricks May 4, 2012 at 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.

  26. Douglas Hahn June 27, 2012 at 3:12 pm

    I found a solution to the Outlook 2010 error “This store does not support rules. Could not complete the operation”.

    Change
    Set st = Application.Session.DefaultStore
    To
    Set st = Application.Session.Stores(1)

    Seems to work for me. Here’s all my code:

    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.Stores(1)
    ‘ 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

  27. Ed July 7, 2012 at 6:31 pm

    Outlook 2010

    I still seems to be receiving the following error:

    “This store does not support rules. Could not complete the operation”.

    With the following change in place:
    Set st = Application.Session.DefaultStore
    To
    Set st = Application.Session.Stores(1)

    Any suggestions?

  28. NeoGeo August 9, 2012 at 6:58 pm

    I Have multiple in boxes and this run on the my personal one but not on the server I need to run them manually can someone show me how to modify the code or where to modify it to make it work on all inbox I have access to ?

    Thanks

  29. Ronto August 14, 2012 at 5:36 pm

    BTW – Just tried the ‘RunAllRules’ module with Outlook 2013 Preview… seems to work well (a little slower than the native Run Rules Now (and selecting all) but does the job!

  30. Will September 4, 2012 at 6:38 pm

    I use the Run All rules command frequently against my primary inbox, thank you.

    I want to evolve it a bit and need some help. I want to run 5 specific rules against a shared inbox, attaching it to a macro. How do i get the code to run it against a specific folder?

  31. Marcus September 21, 2012 at 3:58 pm

    Worked great! Exactly what I needed. Thanks!

  32. Adrian W September 24, 2012 at 8:05 am

    This can be modified to run rules on the current folder you have selected by adding the second line below (1st & 3rd line for context)

    Set myRules = st.GetRules
    Set cf = Application.ActiveExplorer.CurrentFolder
    For Each rl In myRules

    then add Folder:=cf
    as in:

    rl.Execute ShowProgress:=True, Folder:=cf

    This of course is very helpful to filter shared inboxes.

    • Ian Andrews July 7, 2014 at 1:09 pm

      I found it was necessary to add the cf refinement to make this otherwise brilliant macro work.

    • Asusmin August 13, 2014 at 6:41 pm

      Thanks, This works like a charm.

      But how can I run this only for the unread mails in the selected folder? That would make things faster ya?

      Cheers…!

  33. Diane R October 4, 2012 at 8:09 pm

    LOVE IT!!! I made a few tweaks for what I needed but couldn’t have done it from scratch. Thanks so much for sharing.

  34. Scoot November 28, 2012 at 9:36 am

    This is just what i’ve been looking for,m however, I can’t get it to work.

    When I click the button ( correctly assigned macro) it does absolutely nothing. No error message, nothing. I’m using Outlook 2010.

    In the macro itself, are the comment lines preceded by the ` next to the number 1 or the ‘ near the return key please?

    If I copy and paste the code above, I get red comment lines, if I replace the ` with a ‘ then I get green lines.

    Either way, I can’t get it to work anyway.

  35. pyrocam December 5, 2012 at 10:34 pm

    Scoot :

    This is just what i’ve been looking for,m however, I can’t get it to work.

    When I click the button ( correctly assigned macro) it does absolutely nothing. No error message, nothing. I’m using Outlook 2010.

    In the macro itself, are the comment lines preceded by the ` next to the number 1 or the ‘ near the return key please?

    If I copy and paste the code above, I get red comment lines, if I replace the ` with a ‘ then I get green lines.

    Either way, I can’t get it to work anyway.

    replace the `’s so they go green, or just remove the line entirely
    don’t forget to replace all the speech-marks 🙂

  36. OShon December 16, 2012 at 9:49 pm

    Thats my solution:

    Sub Uruchamianie_regul_outlooka()
    Dim r As Rule, a As Store, ns As NameSpace, f As Folder
    Set f = Application.ActiveExplorer.CurrentFolder
    Set ns = Application.Session
    For Each a In ns.Stores
    DoEvents
    On Error Resume Next
    For Each r In a.GetRules
    ‘Debug.Print r.Name
    If r.Name = “name_of_rule” Then _
    r.Execute ShowProgress:=True, Folder:=f
    Next
    Next a
    Set ns = Nothing
    Set f = Nothing
    End Sub

    regards: MVP OShon

  37. Bea February 12, 2013 at 3:39 pm

    Thanks! Made my mail administration so much easier. Funny that such toolbar shortcut is not default in Outlook.
    Anyone know the solution to connect shortcut keys to run this macro. Eg ctrl+1

  38. Rich Wacholz February 19, 2013 at 7:27 pm

    Hi…
    Just found your site after looking for this very type of code. It runs flawlessly (no errors) and prints out each rule I have, however it does not actually execute the rules. Office 365 2013 Outlook. Any ideas? Thanks.
    …RW

  39. Rich Wacholz February 21, 2013 at 3:09 am

    Rich Wacholz :
    Hi…
    Just found your site after looking for this very type of code. It runs flawlessly (no errors) and prints out each rule I have, however it does not actually execute the rules. Office 365 2013 Outlook. Any ideas? Thanks.
    …RW

    Never mind. I had the wrong Inbox selected when running the script. Works great! Thanks.

  40. Jim George March 4, 2013 at 1:31 pm

    This is exactly what I’m looking to create, but it doesn’t seem to work. After going through your instructions, and running the rule, I get an error box:
    Microsoft Visual Basic
    Compile error:
    Syntax error
    OK or Help

    and the first line of the code “Sub RunAllInboxRules()” get’s highlighted in yellow.

    Any suggestions for fixing this?

  41. pyrocam March 4, 2013 at 7:39 pm

    Jim George :

    This is exactly what I’m looking to create, but it doesn’t seem to work. After going through your instructions, and running the rule, I get an error box:
    Microsoft Visual Basic
    Compile error:
    Syntax error
    OK or Help

    and the first line of the code “Sub RunAllInboxRules()” get’s highlighted in yellow.

    Any suggestions for fixing this?

    Hi Jim, at a quess you need to replace the speechmarks. replace every ” you can find with your own “

  42. David Lachnicht March 12, 2013 at 1:54 pm

    Can I select folder other than Inbox to run the rule against?

  43. pyrocam March 18, 2013 at 7:43 pm

    David Lachnicht :

    Can I select folder other than Inbox to run the rule against?

    I believe there are instructions for this in the comments

    • Kyle Anderson March 28, 2013 at 12:36 pm

      I see there are couple people asking this question, but no answer.

      • pyrocam March 29, 2013 at 10:27 pm

        what about comment #37?

  44. Joey March 19, 2013 at 5:54 pm

    Perfect, thanks. I had to replace the ‘ not the ” but then it ran great.

  45. Darkblaid March 21, 2013 at 3:20 pm

    Hi Guys just trying to adapt this to work in outlook 2003 and i’m getting an error on Dim st As Outlook.Store stating User-defined type not defined and am stumped tbh

    Thanks in advance for any help

  46. Chesare April 4, 2013 at 5:28 am

    Hi everybody!… I need to create a macro that backup all rules from outlook 2010 (client and server).
    Any thoughts on this? Please

  47. viperiv May 31, 2013 at 12:43 pm

    Thank you very much for the script. You noted in your instructions that the single quote may translate incorrectly…..that’s what happened to me. It came across as ` and I changed it to ‘

    Works great and your detailed instructions were an exceptional example of good documentation. Again, many thanks.

  48. matt July 11, 2013 at 4:00 pm

    Brilliant. I removed the two lines that open the dialog box at the end and still worked flawlessly.

  49. Kanban August 27, 2013 at 4:02 am

    Fantastic piece of coding, all very exciting, opens new doors for me, thank you

  50. Mausum Sanfui September 20, 2013 at 9:21 pm

    how can i schedule this macro to run on specific time to run

  51. Alex October 18, 2013 at 1:14 pm

    Hi
    Thanks very much for this, really useful. Would anyone know how to modify the code to EXCLUDE one or two rules, but run all the others?
    Thanks!

  52. Bernard Wortelboer November 27, 2013 at 12:18 pm

    Outlook 2010, with multiple IMAP accounts.

    I received the following error: “This store does not support rules. Could not complete the operation”.

    With the following change in place:
    Set st = Application.Session.DefaultStore
    To
    Set st = Application.Session.Stores(1)

    it didn’t work. So I tried something new: a different number for the store:

    Set st = Application.Session.Stores(2)… didnot work for me

    Set st = Application.Session.Stores(3).

    That worked for my default IMAP account. It is now running smooth !

  53. Ben November 28, 2013 at 5:28 pm

    Hi,
    Is there a way to specify which set of rules per mailbox? I have 2 mailboxes, with different sets of rules and I only want to run the one mailboxes worth. Outlook 2013.
    Thanks
    Ben

  54. Bob February 14, 2014 at 3:33 pm

    Looks like this post was copied directly from an outlookcode article posted 31-MAY-2006. A link or mention of the original article would be a good idea.

    • pyrocam February 14, 2014 at 7:33 pm

      Thanks Bob, yes I am using the code that was not written by me, but the post is mine. I have updated the article to reflect where the code probably came from, as I cant recall where I got this specific code from. You will note it shows up frequently all over the internet

  55. Brandon March 21, 2014 at 6:41 pm

    How can this be modified to run a single rule on all of the folders (and their subfolders) within the inbox?

  56. Brandon March 21, 2014 at 6:49 pm

    Basically, I need to run the single rule with the “Include Subfolders” option checked. See this image:

    h**p://s10.postimg.org/73wa3w5m1/Include_Subfolders.png

  57. Brandon March 21, 2014 at 9:08 pm

    Sorry about the link btw. I figured that rule was just to prevent advertising, so I put *’s in it so I could show you the picture.

  58. Rahul April 4, 2014 at 1:52 pm

    Thanks a lot man !!!!!!!!!!!!!!!!!!!!!
    i was just looking for it…worked like a charm !

    just had to replace & retype single and double quotes again as macro was not working fine when i copied the code.

    if facing compile issue,….just remove and retype all the single and double quotes

    Thanks

  59. Jeff Adair April 10, 2014 at 4:33 pm

    i copied the code and had to do some tweaks like replace the ` with ‘ so everything looks the same now as in the picture , fyi when you copy the code from this page i had to tab the sentences so they line up just like in the picture. i am not big code guy so im learning. my problem now is with this piece of it:
    Sub RunAllInboxRules() when i hit the run button or select compile i get a Compile error : sub or function not defined. i currently have a bunch of rules setup for 1 inbox that is connected to Exchange. I am using Outlook office 2007. here is what i have under module:
    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

    • pyrocam April 11, 2014 at 3:37 am

      Sorry Jeff I am no longer actively supporting this. I can’t see anything wrong with your code. Although just to confirm, the lines that start with ‘ are green (these are comments you can delete them and you replaced every ” with a your own ” right?
      Is there any code outside of the sub …. end sub ? there shouldn’t be.

  60. Jeff Adair April 10, 2014 at 8:11 pm

    hello i need some assistance with the above. Thank you!!

    • Jeff Adair April 10, 2014 at 8:25 pm

      please forgive i didnt see the 24hour approval. thanks

  61. Jason October 7, 2014 at 7:59 pm

    @#60
    Replace:
    If rl.Name = rulename Then
    rl.Execute ShowProgress:=True, Folder:=cf
    runrule = rl.Name
    End If

    With:

    If rl.Name = “excluded rule name” Then
    ‘Do nothing
    elseif rl.Name = “2nd excluded rule name” then
    ‘Do Nothing
    ‘You can continue adding them in this pattern
    ‘if you have more than two.
    else
    rl.Execute ShowProgress:=True, Folder:=cf
    runrule = rl.Name
    End If

  62. Robert March 16, 2015 at 6:15 am

    I see this is no longer “actively” supported, but I am seeking to automate processing a select group of rules. I would like to create a new rule that upon execution will run a script or batch file that then executes said rules. Like so many others I get a lot of alerts and when away from my computer, it would be nice to move those out of the way so I can see more important messages.
    The idea:
    send myself an email with specific words to trigger batch or script to running the rules
    have the rules process and my working inbox (not the default inbox) cleaned up by moving alert messages to their archive folder.

    I am comfortable with batch files, but not scripting. I never got this working, but I added three lines to the script so that hopefully three rules would run (I saw the next hoping that would work). I have also tried naming the script *.vbs hoping I could fire it from explorer, but that did not work either. Some means of remote firing this would just be the bomb, but I would want to setup multiple variations so that I could run rules 1-3 and or 4-5. At this point I’d not need to run more than 5 rules, but of course if this was to work that could change.
    Thanks to anyone willing to assist!
    Robert

    P.S. I LOVE the captcha replacement below! – I SO HATE those things as I constantly have to re-enter them!

  63. Eldakka May 18, 2015 at 6:34 am

    OK, rather than having to manually (relatively speaking)
    1) create a new macro for each rule;
    2) create toolbar;
    3) add each macro to the toolbar;
    repeat 1 and 3 each time you add a new rule…

    could some bright spark write a macro that scans all rules, creates a macro for each rule (using the one already provided here as a template), then (if the toolbar doesn’t exit) creating the toolbar and adding all the ‘rules macros’ to it?

    Hopefully it can just add new rules macros if it’s re-run later, checking first which rules already have a macro for them (get list of rules, look for macros that reference them, probably have a standard name here! “apply_” for example), and only continue for the ones that don’t exist.

    If its not possible to just pick out the ones that don’t exist, maybe it could drop all the ‘commands’ in the toolbar and re-create them all…

    if necessary it could either:

  64. Gal Baras November 25, 2015 at 12:40 am

    After cleaning up the smart quotes and linking to the button, I’m getting this:

    Run-time error ‘-1040973553 (c1f4010f)’:

    Automation error

    This is in Outlook 2007 and I can’t find any online references to this error 🙁

    • pyrocam November 25, 2015 at 1:23 am

      Don’t forget that googling with a hypen (minus) changes the search results
      /kb/983265 although this doesn’t seem to match up with what your seeing. If you know how code works a little, try deleting blocks of code until you find the one that’s causing the issue.

      • Gal Baras November 25, 2015 at 5:41 am

        Yes, I only searched for the error code, along with “automation error” and VBA and got nada.

        The problem was with one of my rules, which somehow ran manually, but not in the macro. I added Print statements and logged the loop iterations, while moving rules around until I found it.

        Phew. I’m gonna really like this one-click rule running. Thank you!

  65. wschloss June 7, 2016 at 4:23 pm

    Hi thanks for this. Mine works but doesn’t actually FIND any rules to execute. I suspect my rules are being “stored in the wrong place” as I have, over years, gone through a series of Windows and Office upgrades, and now on MS Office Home and Business 2016 (installed locally, paid, not web-based) under Windows 10, with all updates current. Any ideas how to find where my rules are actually being stored, and either change that, or point correctly within the macro?

    “C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE”

    I see this is an old thread, thanks for any help

  66. wschloss June 7, 2016 at 4:35 pm

    PS: what I have tried: recreating rules from scratch.
    On my current laptop Windows 10 was pre-installed, and ONLY Office 2016 was ever installed (not upgraded). Windows updates are turned on automatic and up-to-date. 8gb RAM, I7 lots space, new machine.

    When I run the macros I get the success message, but no rules are listed. In other words “runrule” is empty. Appears as “” when I step through. No error messages.
    Thanks.

  67. wschloss June 7, 2016 at 4:44 pm

    Sorry, one more thing; my email is now IMAP/SMTP, Would that affect where the rules are stored?
    Windows profile path: c:\users\myname\appdata ..\applicationdata ..\documents ..\local settings etc.
    Thanks.

  68. wschloss June 7, 2016 at 5:00 pm

    Last post I promise, writing this is forcing me to think about. Two clarifications:
    1. All rules run fine from “Run Rules Now”
    2. I mentioned the clean install of Windows and Outlook, however, to preserve settings, defaults and data, after purchasing this laptop with Windows 10 but BEFORE installing Office 2016 I did a selective but thorough copy of my user profile from a previous Windows 7 machine. Prior to that copy I had done a “squeaky cleanup” of that machine with ccleaner64. The Win 7 machine never had any problems (occasional overheating caused me to replace), and the Windows 10 machine has never had any other problems or significant glitches or hiccups since.

  69. pyrocam June 8, 2016 at 3:08 am

    Hi Wschloss, I tested the ability for the macro to read rules in 2016 and it does work. this is the code I have used. to confirm it can read the rules
    (this goes right below the ‘Set myRules = st.GetRules’

    ‘ iterate all the rules
    For Each rl In myRules

    MsgBox rl.Name

    Next

    If it shows there but not below I wonder if the rule type that you have is not rl.RuleType = olRuleReceive

    try commenting out that line and see if it makes any difference (like so)
    ‘ iterate all the rules
    For Each rl In myRules

    rl.Execute ShowProgress:=True
    count = count + 1
    ruleList = ruleList & vbCrLf & rl.Name

    Next

  70. pyrocam June 8, 2016 at 3:19 am

    Also try creating a new basic rule that does something simple that you can test it with, I know sometimes you need to re-create rules after changing outlook profiles. if that rule works but the old ones don’t you might be forced to re-create your rules

  71. wschloss June 13, 2016 at 3:34 pm

    Thanks Pyrocam, when I do that Outlook returns a rule name that matches one of my other email account names, for which I never had any rules, I tried deleting ALL Outlook rules, closing Outlook then recreating one rule–same thing. I am creating the rule from the inbox of my primary account and the rule is simple; categorizes email from a specific sender, then stops processing more rules (I took that last part out but same thing). This leads me to believe even more that the problem is related to where the rules are being stored, so I tried this line of code:

    MsgBox Application.Session.DefaultStore

    And bizarrely Outlook returns yet a different email address (I have 9 active)

    Then when I run this line:

    Application.Session.DefaultStore.GetRules.Item(vRuleName).Execute

    It tells me the object can’t be found (I am stepping through and the variable is correct and I can see it) The rule still runs fine manually)

    I think there must be a registry key that tells Outlook where to store rules, and yet another that is accessed when they are run from macro, and I have a mismatch? How do I find that?

    I just searched the registry for my rule name but did not find.

    Arrghh this is taking too much time

  72. pyrocam June 13, 2016 at 8:20 pm

    Ok. hmmm. I haven’t had to do this before but maybe that the store with the rules isn’t the default store. (Do you specify which profile each time you start outlook?)

    you can try this to determine which store to use

    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
    ‘turn this back on as not all stores support rules

    For i = 1 To Application.Session.Stores.count
    ‘iterate through the stores looking for the one with the right number of rules

    Set st = Application.Session.Stores(i)
    Set myRules = st.GetRules
    MsgBox i & ” = ” & myRules.count
    ‘this will pop up with each store ID and the number of rules
    Next

    End Sub

    it will do a popup for each store (numerical ID) and how many rules are in there.
    lets say you get
    1 = 0
    2 = 1
    3 = 9
    4 = 0
    5 = 0
    etc
    then you know you should be using store 3 and can replace
    Set st = Application.Session.DefaultStore
    with
    Set st = Application.Session.Stores(3)

  73. Sebastian June 17, 2016 at 8:49 am

    Hi,

    I’ve used the macro below to run rules from a button:

    ________________________________________________________
    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
    count = count + 1
    End If
    Next

    Set rl = Nothing
    Set st = Nothing
    Set myRules = Nothing
    End Sub
    ________________________________________________________

    It’s worked perfectly in outlook 2010.
    Now I’ve migrated to the outlook 2016 and simple copy paste.
    It does it’s work but….
    after running I receive
    “Run-time error’ -1387003391 (ad540201)’:
    Automation error”

    when I press debug “Next” is pointed in yellow.

    Can anybody help me and solve this issue? cause I’m not a Visual Basic aware user.
    Thanks in advance!

    Regards
    Sebastian

Leave a Reply

Name *
Email *
Website

Protected by WP Anti Spam