• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • 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?
Thanks.
0
jockovonred
Asked:
jockovonred
  • 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)
        Next
    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
                olFolder.Items(intCounter).Delete
            Next
        End If
    End If
    If (olFolder.Folders.Count = 0) And (olFolder.Items.Count = 0) Then
        olFolder.Delete
    End If
    Set olFolder = Nothing
End Sub
'Macro Ends Here

Cheers!
0
 
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.
0
 
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.

Thanks.
0
 
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?

Thanks.
0
 
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.  
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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