# vba macro to enable 10 outlook rules



## huat8888 (Nov 25, 2018)

Hi all,


I need a help to build an outlook macro so that i can attached it to an outlook button to quickly turn on or off 5 of my selected outlook rules.
The requirement is to enable/disable the 5 rules altogether and there is NO need to run the rule in any of the existing folders/inbox when the rule is enabled. 

Rules to turn on and rule name as below:
Sysalert1
new
criticalnotification
warnings
Weekly

Thank you for your help and advise in advance!


----------



## John_w (Nov 26, 2018)

Try this to enable the rules:

```
Public Sub Enable_Rules()

    Dim outRules As Outlook.Rules
    Dim outRule As Outlook.Rule
    Dim ruleNames As String
    
    ruleNames = ",Sysalert1,new,criticalnotification,warnings,Weekly,"
    
    Set outRules = Application.Session.DefaultStore.GetRules
    For Each outRule In outRules
        If InStr(1, ruleNames, "," & outRule.Name & ",", vbTextCompare) Then
            outRule.Enabled = True
        End If
    Next
    outRules.Save

    Set outRule = Nothing
    Set outRules = Nothing

End Sub
```
Disabling the rules is similar, except use outRule.Enabled = False.  As shown, make sure there is a comma at the start and end of each rule name.


----------



## Fluff (Nov 26, 2018)

Cross posted https://www.excelforum.com/outlook-...o-to-enable-10-outlook-rules.html#post5016174

While we do not prohibit Cross-Posting on this site, we do ask that you  please mention you are doing so and provide links in each of the threads  pointing to the other thread (see rule 13 here along with the  explanation: Forum Rules).
  This way, other members can see what has already been done in regards  to a question, and do not waste time working on a question that may  already be answered.


----------



## John_w (Nov 26, 2018)

*huat8888*, as I've posted a solution to your question and you've cross-posted it, please post links to this thread in your other threads so that other people don't spend time answering a question that's already been answered.


----------

