Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to count number of subfolders under certain folder in Outlook?

Supposing you have created some folders under a root folder. Now you want to know how many subfolders under the root folder, how can you do? Just expand the root folder and manually count all subfolders one by one? This article will introduce an easy method for you to achieve it.

Count number of subfolders with VBA code

Office Tab - Enable Tabbed Editing and Browsing in Office, and Make Work Much Easier...
Kutools for Outlook - Brings 100 Powerful Advanced Features to Microsoft Outlook
  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by rules; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails at once; Auto Add Greeting when reply; Auto Add Date&Time into subject...
  • Attachment Tools: Auto Detach, Compress All, Rename All, Auto Save All... Quick Report, Count Selected Mails, Remove Duplicate Mails and Contacts...
  • More than 100 advanced features will solve most of your problems in Outlook 2010-2019 and 365. Full features 60-day free trial.

Count number of subfolders with VBA code

The following VBA code can help you count number of subfolders under a certain root folder in Outlook. Please do as follows.

1. Press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy and paste below VBA code into the Code window.

VBA code: count number of subfolders under certain folder in Outlook

Sub CountSubFldsUnderRootFolder()
Dim xRootFolder As Folder
Dim xFolderCount As Long
Dim xFolder As Object
On Error Resume Next
'Set xRootFolder = Outlook.Application.ActiveExplorer.CurrentFolder
Set xRootFolder = Outlook.Application.Session.PickFolder
If TypeName(xRootFolder) = "Nothing" Then Exit Sub
If xRootFolder.Folders.Count < 1 Then
    MsgBox "No subfolders under " & Chr(34) & xRootFolder.Name & Chr(34) & ".", vbInformation, "Kutools for Outlook"
    Exit Sub
End If
For Each xFolder In xRootFolder.Folders
    If xFolder.Name <> "Conversation Action Settings" And xFolder.Name <> "Quick Step Settings" Then
        xFolderCount = xFolderCount + 1
        Call ProcessFolders(xFolder, xFolderCount)
    End If
Next
MsgBox xFolderCount & " subfolders under " & Chr(34) & xRootFolder.Name & Chr(34) & ".", vbInformation, "Kutools for Outlook"
End Sub

Sub ProcessFolders(SubFolder As MAPIFolder, Num As Long)
Dim xSubFolder As MAPIFolder
On Error Resume Next
Num = Num + SubFolder.Folders.Count
For Each xSubFolder In SubFolder.Folders
    Call ProcessFolders(xSubFolder, Num)
Next
End Sub

3. Press the F5 key to run the code.

4. In the opening Select Folder dialog box, select a folder you will count its subfolders, and then click the OK button. See screenshot:

5. Then a Kutools for Outlook dialog box pops up to tell you how many subfolders exist in the specified folder. See screenshot:


Related articles:


Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
 
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.

Be the first to comment.