none
Apply Outlook Rules to messages after they are marked as read RRS feed

  • Question

  • I am trying to find a way to have all unread email collect in my inbox as normal, but as I read through, upon their being marked as "read" rules then run to place them in their folders or assign a category based on sender email, etc. This doesn't seem that complex a wish, but I can't find any way to do it. I'm really just wanting to add "read" as a condition for some of my normal rules. Thoughts? VBA Macro?

    Thanks!


    • Edited by Parker.alex Tuesday, March 11, 2014 5:12 AM
    Tuesday, March 11, 2014 5:10 AM

Answers

  • Hello Alex,

    As far as I know the Rules Wizard doesn't provide an option for read/unread e-mails. You need to choose other criteria for using rules. Moreover, rules can't be used for tracking the read/unread status of e-mails. You need to use macros or develop an add-in if you are going to distribute the code on multiple machines.

    In VBA you can use the following methods for filtering items in the folder:

    1. The Find / FindNext method of the Items class. For example:

    Sub DemoFindNext() 
     Dim myNameSpace As Outlook.NameSpace 
     Dim tdystart As Date 
     Dim tdyend As Date 
     Dim myAppointments As Outlook.Items 
     Dim currentAppointment As Outlook.AppointmentItem 
     
     Set myNameSpace = Application.GetNamespace("MAPI") 
     tdystart = VBA.Format(Now, "Short Date") 
     tdyend = VBA.Format(Now + 1, "Short Date") 
     Set myAppointments = myNameSpace.GetDefaultFolder(olFolderCalendar).Items 
     Set currentAppointment = myAppointments.Find("[Start] >= """ & tdystart & """ and [Start] <= """ & tdyend & """") 
     While TypeName(currentAppointment) <> "Nothing" 
     MsgBox currentAppointment.Subject 
     Set currentAppointment = myAppointments.FindNext 
    Wend 
    End Sub
    

    2. The Restrict method of the Items class. Here is what MSDN states:

    This method is an alternative to using the Find   method or FindNext   method to iterate over specific items within a collection. The Find or FindNext methods are faster than filtering if there are a small number of items. The Restrict method is significantly faster if there is a large number of items in the collection, especially if only a few items in a large collection are expected to be found.

    Sub MoveItems()  
        Dim myNamespace As Outlook.NameSpace  
        Dim myFolder As Outlook.Folder  
        Dim myItems As Outlook.Items  
        Dim myRestrictItems As Outlook.Items  
        Dim myItem As Outlook.MailItem  
      
        Set myNamespace = Application.GetNamespace("MAPI")  
        Set myFolder = _  
            myNamespace.GetDefaultFolder(olFolderInbox)  
        Set myItems = myFolder.Items  
        Set myRestrictItems = myItems.Restrict("[Categories] = 'Business'")  
        For i =  myRestrictItems.Count To 1 Step -1  
            myRestrictItems(i).Move myFolder.Folders("Business")  
        Next  
    End Sub
    

    3. The AdvancedSearch method of the Application class. You can run multiple searches simultaneously by calling the AdvancedSearch method in successive lines of code. Also you can use the Save method of the Search object that is returned to create a Search Folder that will appear in the Search Folders list in the Outlook user interface.

    Public blnSearchComp As Boolean  
      
    Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)  
        Debug.Print "The AdvancedSearchComplete Event fired"  
        If SearchObject.Tag = "Test" Then  
            m_SearchComplete = True  
        End If  
      
    End Sub  
      
    Sub TestAdvancedSearchComplete()  
        Dim sch As Outlook.Search  
        Dim rsts As Outlook.Results  
        Dim i As Integer  
        blnSearchComp = False  
        Const strF As String = "urn:schemas:mailheader:subject = 'Test'"  
        Const strS As String = "Inbox"     
        Set sch = Application.AdvancedSearch(strS, strF, “Test”)   
        While blnSearchComp = False  
            DoEvents  
        Wend   
        Set rsts = sch.Results  
        For i = 1 To rsts.Count  
            Debug.Print rsts.Item(i).SenderName  
        Next  
    End Sub  
    

    It is up to you which way is to choose.

    Finally, the Outlook object model provides the ItemChange event of the Items class. It is fired when an item in the specified collection is changed. So, when the read/unread property is changed the event is fired. Be aware, there is a known limitation - if more than 16 items are added or changed at one time, the event may not fire.

    Tuesday, March 11, 2014 7:58 AM