Skip to main content

How to batch delete all empty folders in Outlook?

Author: Kelly Last Modified: 2025-04-10

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
screenshot of VBA editor inserting code

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.

screenshot selecting folder in Outlook

 

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.

screenshot showing number of deleted folders

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

screenshot after deleting empty folders

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 ProBatch 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!

Instantly unlock Kutools for Outlook with a single click. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2