If you would like to delete all the folders with a specific name, you can use the way introduced in this article. It can help you batch accomplish it via VBA.
At times, you may need to quickly locate all the folders that have a specific name and delete them. For instance, you’ve created folders named as a certain contact’s full name. Now, you delete this contact from your Outlook. In the same time, you may also want to batch delete these folders. It is troublesome to find and delete them one by one. Hence, in the followings, we will introduce a method to batch delete them in one go.
Batch Delete All Folders with a Specific Name
- At first, launch Outlook program.
- Then, get access to VBA editor with reference to “How to Run VBA Code in Your Outlook“.
- Next, copy and paste the following VBA code into a module.
Dim strFolderName As String Sub BatchDeleteAllFoldersSpecificName() Dim objOutlookFile As Outlook.Folder Dim objFolder As Outlook.Folder Dim lTotalCount As Integer 'Enter the specific name strFolderName = InputBox("Enter the specific folder name:", , "Test") If strFolderName <> "" Then Set objOutlookFile = Outlook.Application.Session.PickFolder If Not (objOutlookFile Is Nothing) Then lTotalCount = 0 For Each objFolder In objOutlookFile.Folders If objFolder.Name <> "Deleted Items" Then Call ProcessFolders(objFolder, lTotalCount) End If Next strMsg = lTotalCount & " folders have been deleted!" MsgBox strMsg, vbInformation + vbOKOnly End If End If End Sub Sub ProcessFolders(ByVal objCurFolder As Outlook.Folder, ByRef lCount As Integer) Dim objSubfolder As Outlook.Folder 'Delete the folder of the specific name If objCurFolder.Name = strFolderName Then objCurFolder.Delete lCount = lCount + 1 End If 'Process all subfolders recursively On Error Resume Next If objCurFolder.Folders.Count > 0 Then For Each objSubfolder In objCurFolder.Folders Call ProcessFolders(objSubfolder, lCount) Next End If End Sub
- After that, move cursor in the first subroutine.
- Later, click “Run” icon in the toolbar.
- Subsequently, in the small popup dialog box, input the specific folder name to be found.
- Then, in the “Select Folder” dialog, select the specific Outlook file.
- When macro finishes, you’ll get a message which prompts of the count of the deleted folders, as shown in the following screenshot.
- Now, you can check the folder list. All the folders with the specific name have been deleted (moved to “Deleted Items” folder).
Refrain Outlook from Corruption
Outlook is vulnerable, which has been an unquestioned fact. Therefore, if you are not willing or ready to come across Outlook data corruption, you have to back up your Outlook data files regularly. Besides, in reality, it is essential to keep a robust Outlook PST repair tool in vicinity, like DataNumen Outlook Repair. It is able to recover PST data with effortless ease in the event of Outlook corruption.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged mdf and outlook repair software products. For more information visit www.datanumen.com