Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Update Rules; Don't Miss Emails From Actual People!

0.00/5 (No votes)
14 Feb 2014 1  
Update Rules With Exception on Reply and Forward

Introduction

I recently fell very far behind on a project, because I wasn't aware it had started until my boss asked me where I was on it. Come to find out that I was moving emails from services into a folder I had named "Daily Processes" and when a person in my group found an exception within a service, he replied to the email the service sent. An entire conversation with action items continued from that email and I never once knew a thing about the project to fix the service.

I decided I needed to either get rid of all my rules, which I had a LOT of, or figure out some way to get replies from these services in my main inbox folder. Well, I couldn't delete my rules because I get thousands of emails a week and I would be inundated again with emails that mean little to nothing to me. I knew there was an exception property to rules that could be set, but I didn't want to spend the time going through every single one of those rules. Plus, I wanted to see if it could be done through a macro.

Using the Code

You'll have to set up your Outlook to allow development, and you'll have to enable macros for a brief time. I do not recommend leaving this setting on, though. Once you have run the code, you may turn it back off if you choose to do so.

To enable macros: Go to File -> Options -> Trust Center -> Trust Center Settings -> Macro Settings -> Enable All Macros. For some reason, the change in the trust center didn’t register until I closed Outlook completely. You may have to do that as well if you’ve had Outlook open for days like I did.

To see the Developer tab: Click the File tab -> Click Options -> Click Customize Ribbon -> Under Customize the Ribbon and under Main Tabs, select the Developer check box. Now you should be able to get into the VB code part by going into the Developer tab and clicking the Visual Basic button (Alt+F11 for you hot-key gurus).

Add references: In the Visual Basic editor, go to Tools ->References -> Then add in the Visual basic For Applications and Microsoft Outlook 14.0 Object Library.

Copy in the code. I believe you can do this in the main window. You might have to double click on the ThisOutlookSession. Or you can add a new module, which is what I did. Personally, I like to have separate modules per macro.

Sub LoopThroughRulesAddSubjectExceptionForwardReply()
    Dim colRules As Outlook.Rules
    Dim oRule As Outlook.Rule
    Dim oExceptSubject As Outlook.TextRuleCondition
       
    'Get Rules from Session.DefaultStore object
    Set colRules = Application.Session.DefaultStore.GetRules()
    
    For i = 1 To colRules.Count
        'get a single rule
        Set oRule = colRules.Item(i)
        
        'get the exception on that rule
        Set oExceptSubject = oRule.Exceptions.Subject
        
        If Not oExceptSubject.Enabled Then
            oExceptSubject.Enabled = True
        End If
            
        If TypeName(oExceptSubject.Text) <> "String()" Then
            oExceptSubject.Text = Array("RE:", "FW:")
        End If
    Next
        
    colRules.Save
End Sub 

Press F5 and let it run.

Points of Interest

Remember that there is no really good way to reference a Reply of a Forward when it comes to rules. I simply chose the text "RE:" and "FW:" and hope that whoever is emailing me is using a system that also employs this standard.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here