Avatar of a4driver_
a4driver_

asked on 

Macro to execute certain rules in Outlook

Has anyone written any code for an Outlook Macro that will execute certain rules created in Outlook rules?  I am thinking that I could use a macro that will run either at a certain time of day or on manual execution to file emails from Inbox to the appropriate file folders for storage.  If I CATEGORIZE them "OK  to file" for example.
Outlook

Avatar of undefined
Last Comment
a4driver_
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Modified to specifically process two rules for example, (Modify the olkruleset array to reflect the rules you want to be run) it looks like this:

Chris
Sub Run_RuleSet()
Dim olkRuleSet() As Variant
Dim olkRule As Variant
Dim olRules As Outlook.Rules
Dim olRule As Outlook.Rule
Dim intcount As Integer
Dim strStatus As String
 
    olkRuleSet = Array("Rule1", "Rule2")
    Set olRules = Application.Session.DefaultStore.GetRules
 
    strStatus = "All Outlook rules enabled and Run:" & vbCrLf
    For Each olkRule In olkRuleSet
        Set olRule = olRules(olkRule)
        olRule.Enabled = True
        olRule.Execute ShowProgress:=True
        intcount = intcount + 1
        strStatus = strStatus & vbCrLf & intcount & ". " & olRule.Name
    Next
    olRules.Save
    MsgBox strStatus, vbInformation, "Outlook Rule Automation."
 
    Set olRules = Nothing
    Set olRule = Nothing
End Sub

Open in new window

This is version dependant, the defaultstore capability was added in Outlook 2007 so if using an earlier version you are stuck as it isn't possible.

Chris
Avatar of a4driver_
a4driver_

ASKER

Chris,

Thanks.  I tried to create the Macro and did BUT it gives me an error stating that the Macros are disabled.  How do I enable the Macros?
Avatar of a4driver_
a4driver_

ASKER

I am using 2007
Avatar of a4driver_
a4driver_

ASKER

THANKS Chris
Outlook
Outlook

Microsoft Outlook is a personal information manager from Microsoft, available as a part of the Microsoft Office suite. Although often used mainly as an email application, it also includes a calendar, task manager, contact manager, note-taker, journal, and web browser.

105K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo