Outlook VBA Script - Delete folders containing substring "_0"

Created by Andrew Schott, Modified on Mon, Oct 31, 2022 at 10:02 PM by Andrew Schott

Sub EnumerateFoldersInStores()

 

 Dim colStores As Outlook.Stores

 

 Dim oStore As Outlook.Store

 

 Dim oRoot As Outlook.Folder

 

 

 

 On Error Resume Next

 

 Set colStores = Application.Session.Stores

 

 For Each oStore In colStores

 

 Set oRoot = oStore.GetRootFolder

 

 Debug.Print (oRoot.FolderPath)

 

 EnumerateFolders oRoot

 

 Next

 

End Sub

 

 

 

Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder)

 

 Dim folders As Outlook.folders

 

 Dim Folder As Outlook.Folder

 

 Dim foldercount As Integer

 

 

 

 On Error Resume Next

 

 Set folders = oFolder.folders

 

 foldercount = folders.Count

 

 'Check if there are any folders below oFolder

 

 If foldercount Then

 

 For Each Folder In folders

 


If InStr(oRoot.FolderPath, "_0") > 0 Then

    Folder.Delete

    

 End If


 

 EnumerateFolders Folder

 

 Next

 

 End If

 

End Sub


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article