Contact

admin

About Me · Send mail to the author(s) E-mail · Twitter

At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.

Feed Icon

Tags

Open Source Projects

Archives

Blogs of friends

Now playing [?]

Error retrieving information from external service.
Audioscrobbler/Last.fm

ClustrMap

Outlook Macro: Mark All Items Read In Subfolders

Posted in Office at Thursday, September 18, 2008 5:29 PM W. Europe Daylight Time

Mailing lists Recently my mailing lists subscriptions grew to an extend not seen before, largely due to my grown interest in ALT.NET and open source projects. Having an eye on the dev or user mailing lists is often very valuable to stay on top of recent developments, identify best practices and to post or answer the occasional question.

However, that doesn't come without drawbacks. One increasing hassle is to keep up with the constant flow of information such that I see myself forced to reset once in while. After getting back from a 3-day vacation this summer I had 200+ unread feed items and uncounted unread mailing lists messages. I do not claim to read everything that lands in my inbox(es) so a quick "mark all as read" is a very relieving act. FeedDemon, my feed reader, even has a panic button to support this discomforting situation.

Unfortunately Outlook does not support marking all items read in a certain folder and all of its subfolders. On the other hand, there is this ancient VBA language that you can use to program Outlook…

Sub MarkAllRead()
    Dim resultFolder As folder
    Dim folder As folder
    Dim item As MailItem
        
    Set resultFolder = GetFolder("path\to\your\mailing\lists\root\folder")
    
    For Each folder In resultFolder.folders
        For Each item In folder.Items.Restrict("[unread] = true")
            item.UnRead = False
        Next
    Next
             
    Set resultFolder = Nothing
    Set folder = Nothing
    Set item = Nothing
End Sub

Function GetFolder(strFolderPath As String) As MAPIFolder
    ' strFolderPath needs to be something like
    '   "Public Folders\All Public Folders\Company\Sales" or
    '   "Personal Folders\Inbox\My Folder"
    
    Dim colFolders As Outlook.folders
    Dim objFolder As Outlook.MAPIFolder
    Dim arrFolders() As String
    Dim i As Long
    On Error Resume Next
    
    strFolderPath = Replace(strFolderPath, "/", "\")
    arrFolders() = Split(strFolderPath, "\")
    
    Set objFolder = Application.GetNamespace("MAPI").folders.item(arrFolders(0))
    If Not objFolder Is Nothing Then
        For i = 1 To UBound(arrFolders)
            Set colFolders = objFolder.folders
            Set objFolder = Nothing
            Set objFolder = colFolders.item(arrFolders(i))
            If objFolder Is Nothing Then
                Exit For
            End If
        Next
    End If
    
    Set GetFolder = objFolder
    Set colFolders = Nothing
End Function

Thanks to Lars Keller for the hint to filter unread items with Restrict()!

Thursday, January 07, 2010 2:19:01 PM (W. Europe Standard Time, UTC+01:00)
Very good, I was looking for this actaully

Thank you
Harold
Monday, February 01, 2010 3:45:27 PM (W. Europe Standard Time, UTC+01:00)
Hi, thanks for this.

I'm getting an error on debug for resultFolder As folder: "User-defined type not defined."

I'm a VBR macro noob and have a feeling I'll run into errors all along the way. But any help you can offer would be appreciated.
All comments require the approval of the site owner before being displayed.
(will show your gravatar icon)
 
[Captcha]Enter the code shown (prevents robots):

Live Comment Preview