Wednesday, June 17, 2009

Periodically run outlook rules

I have a Windows Mobile 6.1 smart phone which I really like using. The thing that really bugged me though was when I would receive an email, my rules would run on the Exchange server and send my mail off into different folders. The only way that I would know that I had a new email on my phone would be if I drilled down into my different folders to check. The new email notification only appears if the email is in the inbox.

Now the main problem I had was that I would have to leave all my rules in Outlook disabled for a few days and then after that would go through and tick all the rules to run to clean up my inbox. There is no way in Outlook to enable or disable all the rules in a simple way. I have so may rules sorting my email that unticking and ticking each rule to "Run Now" just wasnt realistic. Sooooo I have written a Macro for Outlook that enables and disables rules with the push of a button. The code is at the bottom of this.

To get it working you start Outlook then go into Tools / Macro / Visual Basic Editor. Then on the toolbar just below the File Menu there should be a little drop down arrow. Click on the arrow and choose module. This will open up a new window on the right. Simply paste the code into that and then save and exit.

Now, having closed the Visual Basic window and being back in the main outlook window click on Customize, then the toolbars tab and then New and give your toolbar a name you like.

Once you have done that click back on the commands tab and choose macro. On the right you should see 2 commands. Project1.EnableRules and Project1.DisableRules. Drag each of rules onto the new toolbar that you just made (it will be floating around on your screen somewhere) and hey presto you are done.

Only thing left to do is to change your macro security so that they can run. In outlook click on Tools / Macro / Security and check warnings for all Macros. You will get a pop up each time you try and run this but just click enable macros and it will go away until the next time you close and open outlook. I wouldnt advise turning macro security all the way off.

Now whenever you want to turn all your rules on or off you just click on the respective button....easy as pie.

Here is the code you need...enjoy.

Sub DisableRules()

Dim Rules As Outlook.Rules
Dim OutlookRule As Outlook.Rule
Dim counter As Integer
On Error Resume Next

Set Rules = Application.Session.DefaultStore.GetRules

For Each OutlookRule In Rules
OutlookRule.Enabled = False
counter = counter + 1
Next

Rules.Save

Set Rules = Nothing
Set OutlookRule = Nothing

End Sub

Sub EnableRules()

Dim Rules As Outlook.Rules
Dim OutlookRule As Outlook.Rule
Dim counter As Integer
On Error Resume Next

Set Rules = Application.Session.DefaultStore.GetRules

For Each OutlookRule In Rules
OutlookRule.Enabled = True
OutlookRule.Execute ShowProgress:=True
counter = counter + 1
Next

Rules.Save

Set Rules = Nothing
Set OutlookRule = Nothing

End Sub

No comments:

Post a Comment