Outlook 2007 autopurge
![outlook 2007 autopurge outlook 2007 autopurge](https://i.ytimg.com/vi/HgoLkzrwUEg/maxresdefault.jpg)
Private Sub myExplorer_BeforeFolderSwitch(ByVal NewFolder As Object, Cancel As Boolean) Set myNameSpace = Application.GetNamespace("MAPI") Set myExplorer = Application.ActiveExplorer Public myNameSpace As NameSpace 'Parent folder Public WithEvents myFolder As Folder 'for trapping mail deletion in main outlook window Public WithEvents myExplorer As Explorer 'for folder reference
Outlook 2007 autopurge windows#
Public WithEvents myInspector As Inspectors 'for trapping new windows Public WithEvents myItem As MailItem 'for trapping deletion of opened mail
Outlook 2007 autopurge code#
You can either copy/paste this code or download outlookimapfix.txt (Tools/Macro/Visual Basic Editor) See the screenshots below for help.īe sure you are in 'ThisOutlookSession' before pasting the code To use this code, copy and paste it into 'ThisOutlookSession' in the VBA editor. Outlook will need to be restarted after adding this code
Outlook 2007 autopurge update#
Update June 1st, 2009: Added check for Trash folder items so you can actually delete something that's in the trash Update February 7th, 2010: Received several emails of people having problems using the specified code, changed code to look for folder named "Deleted Items" which is the default Outlook trash folder name. When you do something that would cause an item to be deleted (press delete, click the X on the toolbar) it will check to see if we have a folder named 'Trash' under the root folder, and if so, it will move the email to that folder. So basically this is what the code does: When you start Outlook, the script will create references so that it can watch as events happen. This meets all of my needs and is transparent to the user. I've chosen to simply have outlook hide the items marked for deletion, and the folders auto-purge when changing (defined in the account settings). There are a few ways this can be handled. Of course the downside of this is that Outlook simply marks messages for deletion and shows them with a strikethrough. By trapping this event and passing it with my own function, the deleted emails can be moved to a trash folder of my own specification. The difference is that the MoveTo would be Nothing, instead of a destination folder. What I ended up discovering is that a folder would fire the 'BeforeItemMove' even when an item was deleted, whether it was with the delete key or the toolbar button. At first it seemed like the MailItem's 'BeforeDelete' was my answer, but that only handled emails that you opened in it's own window and not any other time.
![outlook 2007 autopurge outlook 2007 autopurge](https://www.isunshare.com/images/article/office/how-to-automatically-delete-emails-in-outlook/automatically-delete-emails-on-server-outlook-2007.png)
I ended up adding inspectors to almost everything and watching as the events fired. I spent some time digging around the MSDN for object reference and getting myself familiar with inspectors and explorers. I've never specifically written any VBA previously, but I have used Visual Basic frequently in the past, so I figured I would at least have an understanding of the language. (see this and this) This solution was not acceptable since an untrained user will not know to do this. Most of the solutions involved incorporating a macro into the toolbar and from there having to highlight the emails to be 'deleted' and clicking an additional button. I spent some time digging around online to find a way to make Outlook handle deleting emails a little more appropriately for an IMAP account. Outlook 2007 should have been the fix for their terrible IMAP implementation, but alas, it was not. If you've used it for IMAP, or attempted to, then I'm sure you've felt my pain. I initially started using IMAP through outlook with version 2003. Microsoft Outlook IMAP delete vbscript workaround fix Fixing Outlook's terrible IMAP deletion handling with vbscript May 26th, 2009 - Written By: Jared Hollingsworth