Outlook has an option to show either the number of unread messages or the total number of messages in a folder.
To change the setting, you right click on the folder, choose Properties then select the desired option, Show number of unread items or Show total number of items.
If you have a large number of folders to change, this task can take a lot of time as you need to change the property on each folder one at a time. You can speed this up using a VBA macro.
If you have multiple data files in your profile and want to change the setting for just one data file, you'll need to use an If statement to check for the data file name. The data file name is the top folder in the folder list and listed in the Properties dialog (in the Location field) when you view the Properties of any folder, as seen in the Properties screenshot above.
After running the macro, select the data file name to refresh the view. All folders, including subfolders, will be updated.
Sub TotalUnreadCount() ' 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 Set Stores = App.Session.Stores For Each Store In Stores Set Root = Store.GetRootFolder ' Use If statemnet to apply to a specific data file ' Otherwise, all folders in ALL data files in the profile are changed ' display name is in the location field of the Properties dialog 'If Root = "data file display name" Then ChangeShowCount Root 'End If Next End Sub Private Sub ChangeShowCount(ByVal Root As Outlook.Folder) 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 'ShowTotal Count Folder.ShowItemCount = olShowTotalItemCount 'Show UnreadCount 'Folder.ShowItemCount = olShowUnreadItemCount ChangeShowCount Folder Next End If End Sub
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor
More Information
Store.GetRootFolder Method (Outlook) (MSDN)
Store Object (MSDN)
Simple and necessary function. Not proposed as a basic in outlook.
GREAT thanks to the author, congratulation;
as usual i not proud on the microsoft tool, Microsoft is no longer user oriented for efficiency, more oriented to grow in cheaper developpement and publish low real added value software
Worked great! Thanks Diane.
My apologies. I wrote too soon. I figured out how to reverse this. Thank you again. Very helpful script!
How did you reverse this? Ran the macro and it worked perfectly, now I just need to undo it
What's the trick to reverse this?
Rerun it - changing which line is commented out:
'ShowTotal Count
' Folder.ShowItemCount = olShowTotalItemCount
'Show UnreadCount
Folder.ShowItemCount = olShowUnreadItemCount
ChangeShowCount Folder
Thank you so much! Glad to know there's an undo button. Was a bit worried there for a second.
Hi Diane,
the macro worked great. Thanks much,
Phillip