28 September, 2013 (published)
15 September, 2014 (last modified)

Outlook macro for showing total numbers of items for all folders

  Categories: Outlook-macros
  Tags:  ,

check-listWhen using with Outlook folders the navigation tree can show either how many unread items it contains or how many items it contains. The read-unread status of a message is fragile and not very useful. The number of items in a folder on the other hand is very useful information. Unfortunately the default for newly created folders is the "unread" version. You can probably change this setting somewhere in the registry, but I have not found this (yet). In this post I present a different solution: creating a macro. Fortunately, in contrast to MS Word and PowerPoint enabling macros does not involve changing of file extensions. So you can use the macro yourself without much ado.

In my case I use my collection of email messages as my to-do list. To be more specific: if more than email message is connected to one and the same task I create a new folder in which I put all these emails. In the exceptional case that a task is not reflected in an email message I create a message that I sent to myself or I use "New Post in the Folder". As a result I end up with sometime ten new folders per day. And these show all the irritating number of unread items rather than the number of items as Microsoft determined that to be the default.

Of course I could correct this, one by one for each folder each time. This is cumbersome and irritating. So, I made a VBA script that does the job. Please find the script below.

Sub EnumerateFoldersInStores()
    ' store is a pst file
    Dim App As New Outlook.Application
    Dim Stores As Outlook.Stores
    Dim Store As Outlook.Store
    Dim Root As Outlook.Folder

    On Error Resume Next
    ' all pst files shown by Outlook session
    Set Stores = App.Session.Stores
    'loop over folders in each pst file
    For Each Store In Stores
        Set Root = Store.GetRootFolder
        EnumerateFolders Root
End Sub

Private Sub EnumerateFolders(ByVal Root As Outlook.Folder)
    'recursive function
    Dim Folders As Outlook.Folders
    Dim Folder As Outlook.Folder
    Dim Foldercount As Integer

    On Error Resume Next

    Set Folders = Root.Folders
    Foldercount = Folders.Count
    If Foldercount Then
        For Each Folder In Folders
            Folder.ShowItemCount = olShowTotalItemCount
            EnumerateFolders Folder
    End If
End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

8 reactions op “Outlook macro for showing total numbers of items for all folders”

  1. Nuno says:

    I tried it, how can it be undone?

  2. Nuno says:

    Nevermind, I figured it out, replaced

    Folder.ShowItemCount = olShowTotalItemCount


    Folder.ShowItemCount = olShowUnreadItemCount


  3. Bruce Lerner says:

    Worked perfectly – thank you

  4. Alex says:


    How do I undo this?

  5. Carole-Anne says:

    Hi there…please could you assist me further with this…I have never used macros before and would love it if you could do a step by step for dummies version…I have numerous folders and they all revert back to default on closing and restarting Outlook 2013…kindest regards…Carole-Anne

  6. Carole-Anne says:

    Please help me…x

  7. Gordon says:

    Hi, I’m trying to apply this to some shared mailboxes that are not in cached mode, would you be able to help me modify your code here to suit that purpose?

  8. Deb says:

    Thank you so much. Am working on a user’s mailbox and user has hundreds of folders which I need to just see total number of messages, not unread. Worked great!

Write a reaction

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution.