vba macro to enable 10 outlook rules

huat8888

New Member
Joined
Nov 23, 2018
Messages
7
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!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this to enable the rules:
Code:
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,577
Messages
6,173,164
Members
452,504
Latest member
frankkeith2233

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top