ability to delete multiple folders at once either via a plugin, addon, script, other

Posted on 2005-04-29
Last Modified: 2013-11-18
I would like to delete multiple folders from within Outlook 2003.
The product allows the ability to create many folders under another folder.
For example:
Inbox |
         > Friends
         > Family
         > Other

If you want to delete only one folder, right click and delete the folder.
My folder structure is so huge right now that doing this is very time consuming.
I would like to delete folders which are empty or which do not contain any email items.

I have searched Google and this site but do not seem to find the ability anywhere to do this.
It would be nice if Outlook acted like Windows Exploder so multiple folders could be selected at once and deleted.

Does anyone know of any way this could be done via a plug-in, add-in, script or other method without having to right click and delete each and every folder?
Question by:jockovonred
    LVL 76

    Accepted Solution

    Hi jockovonred,

    Here is some VBA code, a macro, that'll do exactly what you asked for.  It will delete all the folders and items within those folders of an entire folder tree.  To use it, do the following.

    1.  Start Outlook
    2.  Click Tools->Macro->Visual Basic Editor
    3.  If not already expanded, expand Modules and click on Module1
    4.  Copy the code below and paste it into the right-hand pane of the editor window
    5.  Click the diskette icon on the toolbar to save the changes
    6.  Close the VB Editor
    7.  Click Tools->Macro->Security
    8.  Set the Security Level to Medium.  The macro cannot run if the Security Level is High
    9.  Click on a folder in your list of folders
    10.  Run the macro by clicking Tools->Macro->Macros->DeleteFolderTree->Run
    11.  The macro will present you with a dialog-box asking if you want to delete from the selected folder down.  If you click No, then the macro will stop and do nothing.  If you click Yes, then the macro will ripple through the folder tree from that point on down deleting all empty folders.  Folders with items in them will cause a dialog-box to appear again asking if you want to delete the contents.  Clicking Yes will delete all items in the folder.  Clicking No will leave the items and the folder they are in as well as all folders above in that folder's tree.  In other words, it works exactly as Windows Explorer does where non-empty folders cannot be deleted.

    I wrote and tested this using Outlook 2002.  It worked exactly as described.  It should work fine within Outlook 2003 also.  

    'Macro Begins Here
    Sub DeleteFolderTree()
        Dim olRootFolder As MAPIFolder, _
            olExplorer As Outlook.Explorer, _
            intCounter As Integer
        Set olExplorer = Application.ActiveExplorer
        Set olRootFolder = olExplorer.CurrentFolder
        If MsgBox("Delete [" & olRootFolder.Name & "] and all its contents?", vbYesNo, "Delete Folder Tree") = vbYes Then
            DeleteFolder olRootFolder
        End If
        Set olRootFolder = Nothing
        Set olExplorer = Nothing
    End Sub

    Sub DeleteFolder(olFolder As MAPIFolder)
        Dim intCounter As Integer
        If olFolder.Folders.Count > 0 Then
            For intCounter = olFolder.Folders.Count To 1 Step -1
                DeleteFolder olFolder.Folders(intCounter)
        End If
        If olFolder.Items.Count > 0 Then
            If MsgBox("Folder [" & olFolder.Name & "] isn't empty." & vbCrLf & "Delete contents?", vbYesNo, "Delete Folder Contents") = vbYes Then
                For intCounter = olFolder.Items.Count To 1 Step -1
            End If
        End If
        If (olFolder.Folders.Count = 0) And (olFolder.Items.Count = 0) Then
        End If
        Set olFolder = Nothing
    End Sub
    'Macro Ends Here


    Author Comment

    I had Profiles1 in the Tools > Macros > Visual Basic Editor.
    When expanded, it has ThisOutlookSession which I double-clicked, added the above code to under the (General), saved and tested.

    It looks like this appears to do the job.

    Is there a good site to learn more about coding VB scripts for Outlook?
    Thanks for your assistance.
    LVL 76

    Expert Comment

    by:David Lee
    I don't know that it'll hurt to have the code in ThisOutlookSession, but that's not really where it belongs.  

    In my opinion the best site for learning about scripting Outlook is

    Glad I was able to help out.

    Author Comment

    I figured out how to add Module1.
    Right-click 'Microsoft Office Outlook Objects' within the VB script editor.
    Choose Insert and Module.
    I removed the code from 'ThisOutlookSession', placed it in 'Modules1' under (General) and saved both.


    Author Comment

    Is there a way to add other parameters to the code, such as the create date of the folder or is there a way to say any folders greater than this alphabetic character or numeric number, delete?

    LVL 76

    Expert Comment

    by:David Lee
    Outlook folders don't maintain a creation date, or any other dates that I know of, so that one would be out.  Yes, it should be possible to modify the code to only delete folders who's name begins with or contains a certain character or string of characters.  

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    My experience with Windows 10 over a one year period and suggestions for smooth operation
    Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now