• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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

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?
  • 3
  • 3
1 Solution
David LeeCommented:
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

jockovonredAuthor Commented:
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.
David LeeCommented:
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 http://www.outlookcode.com/

Glad I was able to help out.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

jockovonredAuthor Commented:
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.

jockovonredAuthor Commented:
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?

David LeeCommented:
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.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now