Google

2007-10-04

Enable / Disable Outlook 2007 Rules


As a Blackberry user, one of my pain-points is with the pst files. Here is how it goes. Let's say Outlook is open and I get an e-mail, my rules process it and move it to one of the pst folders. Problem is that I don't get it in my BlackBerry.

Of course, if outlook was closed, or if the rules were not processed, that message would end up in my BlackBerry. As I want to keep outlook open, I have to disable the rules. There is no manual way of quickly doing this. If you look at Outlook Rules > Run Rules, you can not, for example, select all with Ctrl+a. You have to click and select each one of them. Painful!

So, I decided to create a macro, that would automatically disable the rules, or enable & run them. Idea is that in the morning, I will keep the rules disabled so that I will get them in my BB, and time to time I will run enable script to move them to psts.

Below is the code. In Outlook, you can
* press Alt+F11
* Expand Project1 (VbaProject.OTM)
* Expand Microsoft Office Outlook Objects
* double click ThisOutlookSession
and paste the code in there.

Then you can simply Press Alt+F8 and chose the action...


Sub DisableAllRules()
Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next

'Get Rules from Session.DefaultStore object
Set colRules = Application.Session.DefaultStore.GetRules

' iterate all the rules
For Each oRule In colRules
oRule.Enabled = False
count = count + 1
ruleList = ruleList & vbCrLf & count & ". " & oRule.Name
Next

colRules.Save

' tell the user what you did
ruleList = "These rules were enabled: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: DisableAllRules"

Set colRules = Nothing
Set oRule = Nothing
End Sub

Sub Enable_Run_AllRules()
Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next

'Get Rules from Session.DefaultStore object
Set colRules = Application.Session.DefaultStore.GetRules

' iterate all the rules
For Each oRule In colRules
oRule.Enabled = True
oRule.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & count & ". " & oRule.Name
Next

colRules.Save

' tell the user what you did
ruleList = "These rules were enabled: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: EnableAllRules"

Set colRules = Nothing
Set oRule = Nothing
End Sub
Post a Comment