Outlook macro to permanently delete items in junk email folder
If you are anything like me you hate using the mouse to right click on your Outlook Junk E-mail Folder to select Empty "Junk E-mail" Folder and then on top of that you have to click Yes when it asks you "Are you sure you want to permanently delete all the items and subfolder in the "Junk E-mail" folder?". I hate doing that and I'm more of a hotkey kind of person so I wanted some way to do this with a hotkey.
A while ago I remember KC Lemson posted a macro to delete the items in your Junk E-mail folder, which works great except that it just puts the items from the Junk E-mail folder into the Deleted Items folder where as I wanted to permanently delete them. I modified her macro so that it permanently deletes the items from the Junk E-mail folder (well sort of).
In the Outlook Object Model there is no direct way to permanently delete an item, so I found this post which suggested we just delete the item twice, once from the original folder and once from the Deleted Items folder, which seems to be a pretty simple work around. Anyway here is the macro code:
Public Sub EmptyJunkEmailFolder() Dim outApp As Outlook.Application Dim junkFolder As Outlook.MAPIFolder Dim junkItem, deleteItem As Object Dim entryID As String Set outApp = CreateObject("outlook.application") Set junkFolder = outApp.GetNamespace("MAPI").GetDefaultFolder(olFolderJunk) For Each junkItem In junkFolder.Items entryID = junkItem.entryID ' Store item entry id junkItem.Delete ' Delete from junk mail folder ' To permanently delete item find and delete from deleted items Set deleteItem = outApp.Session.GetItemFromID(entryID) deleteItem.Delete Next Set junkItem = Nothing Set deleteItem = Nothing Set junkFolder = Nothing Set outApp = Nothing End Sub
Once you setup this macro you can add a toolbar button and set the accelator key to something unique and then you have a hotkey to permanently delete the items from your Junk E-mail folder. If you need help doing any of those things take a look at KC's macro post which has some good information and links on how to do those things.
Also incase anyone is in search for the Outlook or Office Object Model Documentation here is a link that tells you how to find it (it took me longer than I care to say to find this ;).
UPDATE: This msdn article talks you through how to create a personal ditigal signature so Outlook doesn't complain every time you run the macro.