Skip to main content

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


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:


Best Office Productivity Tools

Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook

🤖 AI Mail Assistant: Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

📧 Email Automation: Out of Office (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

📨 Email Management: Easily Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

📁 Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Boost Your Outlook Productivity with Tabbed Views  /  Minimize Outlook Instead of Closing ...

👍 One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  🕘Show Sender's Time Zone ...

👩🏼‍🤝‍👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Over 100 Features Await Your Exploration! Click Here to Discover More.

Read More       Free Download      Purchase
 

 

Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Ich weiß gar nicht, ob ich hier auch Fragen stellen kann zu gefundenen Makros?Also mache ich es einfach mal, ok?
Das Makro zum Ermitteln der Anzahl von Unterordnern habe ich für meinen Zweck, nämlich in Ordnereigenschaften einzustellen, dass alle Elemente im Ordner angezeigt werden sollen im Verzeichnisbaum links in Outlook habe ich jetzt mal so für mich verändert.
Sub PrivateOrdnerAlleMailsAnzeigen()
Dim xRootFolder As Folder
Dim xFolderCount As Long
Dim xFolder As Object
On Error Resume Next

Neu:
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
xRootFolder.ShowItemCount = olShowTotalItemCount
For Each xFolder In xRootFolder.Folders
xFolder.ShowItemCount = olShowTotalItemCount
xFolderCount = xFolderCount + 1
Next
MsgBox xFolderCount & " Ordner konfiguriert.", vbInformation, "Anzeigeart Elemente im Ordner"
xFolderCount = 1
GoTo Neu
End Sub


Das funktioniert auch gut aber es fehlt noch etwas, das ich nicht wirklich eingebaut bekomme.
Dabei geht es darum, dass einige Ordner unter dem Ordner, der ausgewählt wird, noch Unterordner haben, die im Ablauf aber nicht mit bearbeitet werden.

Deshalb der Weg jetzt über Goto Neu und dann Neuauswahl der Unterordner und zuletzt mit manuellem Abbrechen beenden.

Wenn mal bitte jemand drüber schauen und eventuell dafür eine automatische Lösung hätte, wäre ich Euch dankbar.

Gruß Wolfgang
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations