How To Batch Delete All Empty Folders In Outlook?

You are here:
Table of contents

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

Click Insert > Module, and paste below VBA code into the new module window.

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 'Declare sub folder objects
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 the folder is empty check for subfolders
If xFldr.Folders.Count < 1 Then 'If the folder contains not sub folders confirm deletion
xFldr.Delete 'Delete the folder
xFlag = True
xCount = xCount + 1
Else 'Folder contains sub folders so confirm deletion
FolderPurge xFldr.Folders, xFlag, xCount
End If
Else 'Folder contains items or (subfolders that may be empty).
FolderPurge xFldr.Folders, xFlag, xCount
End If
Next
End If
End Sub

Press F5 Key or Run button to run this VBA code.

In the popping out Select Folder dialog box, please select the specific folder whose empty subfolders you will delete in bulk, and click the OK button.

Now a Kutools for Outlook dialog box comes out and shows you 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 already.

This FAQ comes from the following website:

https://www.extendoffice.com/documents/outlook/4567-outlook-delete-empty-folders.html

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.