Sign in to follow this  
Zoely

outlook problem

Recommended Posts

Hi,

I need to check the total number of items in a folder frequently, But there are a lot of subfolders under this folder. The total number of items which shows in the right of the folder doesn't contain the number of items in its subfolders. So I need to count them by plusing them all by myself.

So my question is that can I just set the outlook to show the total number of items in a folder inculding its subfolders.  How to do that ?

 

Share this post


Link to post
Share on other sites

Yes, you can write VBA codes to do that for you. I just find a macro which may be close to  what you need.

 

Sub CountItems()
    Dim objMainFolder As Outlook.Folder
    Dim lItemsCount As Long
 
    'Select a folder
    Set objMainFolder = Outlook.Application.Session.PickFolder
 
    If objMainFolder Is Nothing Then
       MsgBox "You choose select a valid folder!", vbExclamation + vbOKOnly, "Warning for Pick Folder"
    Else
       'Initialize the total count
       lItemsCount = 0
       Call LoopFolders(objMainFolder, lItemsCount)
    End If
 
    'Display a message for the total count
    MsgBox "There are " & lItemsCount & " items in the " & objMainFolder.Name & " folder Including its subfolders.", vbInformation, "Count Items"
End Sub

Sub LoopFolders(ByVal objCurrentFolder As Outlook.Folder, lCurrentItemsCount As Long)
    Dim objSubfolder As Outlook.Folder
 
    lCurrentItemsCount = lCurrentItemsCount + objCurrentFolder.Items.Count
 
    'Process all folders and subfolders recursively
    If objCurrentFolder.Folders.Count Then
       For Each objSubfolder In objCurrentFolder.Folders
           Call LoopFolders(objSubfolder, lCurrentItemsCount)
       Next
    End If
End Sub

 

And here is the link of the macro, tou can see if  it helps

 

https://www.datanumen.com/blogs/quickly-get-total-count-items-folder-subfolders-via-outlook-vba/

 

Good luck

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this