![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I am attempting to change how Outlook manages the IMAP Delete command.
(Sorry this was posted in the VBA newsgroup but there seems to be almost no activity in that group!) I want to press delete, and have outlook move the item to the Trash folder, then mark the item for deletion and purge the item from the current folder view. I have the following script (Compliments LaFang) to help me do what I want, but it has a few problems. 1. It only runs when I select the macro from the Macros menu. I would like this to be a constantly running rule. 2. It moves the item to the Trash folder, but appears as an unread item in the trash folder. 3. It appears to work wether you are looking at a IMAP account or a POP account, I would like to have it just work in my IMAP accounts. 4. When I press delete, it asks me if I want to purge all the items, I want it to purge the items automagically, without having to press another button. 5. If I am in the Trash folder, the item should be deleted as normally - I get an error that the item cannot be moved. Could anyone help me with this? Thanks! /CL Sub DeleteMessages() Set myOlApp = CreateObject("Outlook.Application") Dim myNameSpace As NameSpace Set myNameSpace = myOlApp.GetNamespace("MAPI") Dim myExplorer As Explorer Set myExplorer = myOlApp.ActiveExplorer 'Get the folder type, expected type is 0 i.e. mail folder. If other type of folder 'being used then abort macro as it should only be used with mail folders. folderType = myExplorer.CurrentFolder.DefaultItemType 'Check that folder is mail folder If TypeName(myExplorer) = "Nothing" Or folderType 0 Then GoTo invalidMailbox End If 'Locate root folder for this account Set thisFolder = myExplorer.CurrentFolder Do Until thisFolder.Parent = myNameSpace Set thisFolder = thisFolder.Parent Loop Set accountFolder = thisFolder 'Identify selected messages Dim selectedItems As Selection Set selectedItems = myExplorer.Selection Dim currentMailItem As MailItem Dim iterator As Long 'Run loop on selected messages For iterator = 1 To selectedItems.Count Set currentMailItem = selectedItems.Item(iterator) 'Move messages to Deleted Items folder Set trashFolder = accountFolder.Folders("Trash") currentMailItem.Move (trashFolder) Next 'Now, purge deleted messages Dim myBar As CommandBar Set myBar = Application.ActiveExplorer.CommandBars("Menu Bar") Dim myButtonPopup As CommandBarPopup Set myButtonPopup = myBar.Controls("Edit") Dim myButton As CommandBarButton Set myButton = myButtonPopup.Controls("Purge Deleted Messages") myButton.Execute Exit Sub invalidMailbox: MsgBox ("Macro configured only to work with mail folders! ") Exit Sub End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Disable 'Shift + Delete' functionality in Outlook | [email protected] | Outlook - General Queries | 2 | April 12th 06 06:10 AM |
vba to change font of notes | Charlie | Outlook and VBA | 3 | March 9th 06 06:51 AM |
Lost functionality | mrniceguyinhannibal | Outlook - Installation | 0 | February 8th 06 04:05 PM |
Change/correct IMAP folder view behavior (always collapsed) | Michel | Outlook - Installation | 0 | January 31st 06 06:27 PM |
Delete Custom Outlook Control thru Access VBA | Sue Mosher [MVP-Outlook] | Outlook - Using Forms | 0 | January 20th 06 05:29 PM |