How to batch delete all empty folders in Outlook?
Suppose there are dozens of empty folders under a mail folder in Outlook. Generally, we can delete the empty folders one by one by right-clicking each folder. Compared to repeatedly right-clicking, this article introduces a VBA script to quickly delete all empty subfolders of one Outlook folder in bulk.
Batch delete all empty folders in Outlook with VBA
Batch delete all empty folders in Outlook with VBA
To remove all empty subfolders of a certain Outlook folder, please do as follows:
1. Press "Alt" + "F11" keys to open the Microsoft Visual Basic for Applications window.
2. Click "Insert" > "Module", and paste the following VBA code into the new module window.
VBA: Delete all empty subfolders of a certain Outlook folder in bulk
Public Sub DeletindEmtpyFolder()
Dim xFolders As Folders
Dim xCount As Long
Dim xFlag As Boolean
Set xFolders = Application.GetNamespace("MAPI").PickFolder.Folders
Do
FolderPurge xFolders, xFlag, xCount
Loop Until (Not xFlag)
If xCount > 0 Then
MsgBox "Deleted " & xCount & "(s) empty folders", vbExclamation + vbOKOnly, "Kutools for Outlook"
Else
MsgBox "No empty folders found", vbExclamation + vbOKOnly, "Kutools for Outlook"
End If
End Sub
Public Sub FolderPurge(xFolders, xFlag, xCount)
Dim I As Long
Dim xFldr As Folder
xFlag = False
If xFolders.Count > 0 Then
For I = xFolders.Count To 1 Step -1
Set xFldr = xFolders.Item(I)
If xFldr.Items.Count < 1 Then
If xFldr.Folders.Count < 1 Then
xFldr.Delete
xFlag = True
xCount = xCount + 1
Else
FolderPurge xFldr.Folders, xFlag, xCount
End If
Else
FolderPurge xFldr.Folders, xFlag, xCount
End If
Next
End If
End Sub

3. Press "F5" or click the "Run" button to run this VBA code.
4. In the popping out Select Folder dialog box, select the specific folder whose empty subfolders you will delete in bulk, and click the "OK" button.

5. Now a Kutools for Outlook dialog box will appear, showing how many empty subfolders have been deleted. Click the "OK" button to close it.

Until now, all subfolders of the specified Outlook folder have been deleted in bulk successfully.

Related Articles
Find folder (full folder path) by folder name in Outlook
Best Office Productivity Tools
Breaking News: Kutools for Outlook Launches Free Version!
Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!
π€ Kutools AI : Uses advanced AI technology to handle emails effortlessly, including replying, summarizing, optimizing, extending, translating, and composing emails.
π§ Email Automation: Auto Reply (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: Recall Emails / Block Scam Emails by Subjects and Others / Delete Duplicate Emails / Advanced Search / Consolidate Folders ...
π Attachments Pro: Batch Save / Batch Detach / Batch Compress / Auto Save / Auto Detach / Auto Compress ...
π Interface Magic: πMore Pretty and Cool Emojis / Remind you when important emails come / Minimize Outlook Instead of Closing ...
π One-click Wonders: Reply All with 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 ...
Use Kutools in your preferred language β supports English, Spanish, German, French, Chinese, and 40+ others!

