tech, vba
6 Comments Outlook VBA Code to Empty Deleted Items Folders
I’ve been working and playing around quite a bit with MS Excel and MS Outlook VBA code and have written quite a few tools / add-ins / functionality / macro code that automates several manual processes. Will try and add as many of these up as possible over time, starting today.
I have multiple personal folders (PSTs) in my MS Outlook profile and have rules set up to automatically move the emails to appropriate folders. When I delete an email, it is sent to the corresponding personal folder’s Deleted Items folder.
Now, MS Outlook has an ‘Empty “Deleted Items” Folder’ menu option, but that only empties the Deleted Items folder in the default mailbox and not the other personal folders. To empty these folders, one manually needs to right-click on each Deleted Items folder and click the ‘Empty “Deleted Items” Folder’ option.
Therefore I wrote this MS Outlook VBA macro code that is used to empty all the Deleted Items folders with one click.
You can download the code here.
To use this in your MS Outlook: Press ALT-F11 in MS Outlook to open the Microsoft Visual Basic editor. Macros need to be enabled and if Macros have not been enabled when you pressed ALT-F11, you will get a prompt to enable the same.
In the Project explorer on the left, right-click on Modules and Insert a new Module. Open the  text file that you downloaded above and copy-paste the code in the module.
To customise the code for your requirements, firstly figure out how many Personal Folders you have and their names.
Add the following code as many times as there are Personal Folders in your outlook profile, and replace “Friends” with your Personal Folder name:
‘***Empty Personal Folders Deleted Items Folder
‘Change the current folder to the target personal folder / pst name
Set personalFolder = mNameSpace.Folders(“Friends”) ‘Friends is the name of the Personal Folder
Set objExpl.CurrentFolder = personalFolder.Folders(“Deleted Items”)
‘Select the target folder
objExpl.SelectFolder personalFolder.Folders(“Deleted Items”)
‘Get the Empty Deleted Items command = UID 1671
Set objCBB = objExpl.CommandBars.FindControl(, 1671)
‘Execute the command
objCBB.Execute
At present the code has details of two Personal Folders (Friends and Family)
To run the above code you can press ALT-F8 (or go to Tools -> Macro -> Macros) and then select EmptyDeletedItems and click Run.
You may also add a shortcut button to the Toolbar, so you can run the macro in one click. For this right-click on the Toolbar and click on Customize. Click on the Commands tab and then select Macros as the Category and then drag and drop the EmptyDeletedItems macro command to a location on the Toolbar.
Running the macro now empties all the Deleted Items folders, in all the Personal Folders and the default Mailbox.
Download the code here.
[...] that links to that macro. I’ve uploaded the macro along with instructions on how to use it here – http://sabarish.net/blog/archives/437 Do let me know if that solves your problem. Cheers, Sabarish "Tyler G." wrote: > I [...]
Hi,
I came across your article when I decided to create separate PST files for each email account and realized there isn’t a logical way to remove deleted emails. Thanks to your code I managed to deal with the problem quite quickly..
but I’m wondering if you actually tested your code and it was working for you?
You are calling UID 1671 which is the main Empty “Deleted Items” Folder and as such it’s emptying only the default account, no matter if you selected another one.
So the solution is to enter the respective deleted items folder, loop through it and remove all items.
I thought I’d let you know ;)
-src-
Hey Searcher!
Thanks for bringing that to my notice! I had actually uploaded the wrong code. For representational purposes I had copied and pasted that repeating section from the main deleted items folder and forgot to change the values. I’ve uploaded the new version now.
You don’t need to loop through all files – you can do a select all (ID 756) and delete (ID 478) directly.
Cheers,
Sab
I am using your code, but I get the message pop-up asking if I am sure I want to delete the items. How do I get rid of that pop-up and just have the items deleted?
Nevermind, I found it in the Outlook Program.
Tools>Options>Other>Advanced Options>
Uncheck “Warn before permenantly deleting items.”
Best
[...] Yet ]Sabarish Raghupathy runs a personal blog but one of his articles has some Outlook VBA code to empty the Deleted Items folders for multiple mailboxes. Visit the article for the full code.The code works well but requires some hardcoding of mailbox [...]