A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - General Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Using VBA to Change IMAP Delete functionality



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old May 30th 06, 05:53 AM posted to microsoft.public.outlook
EastAsia
external usenet poster
 
Posts: 20
Default Using VBA to Change IMAP Delete functionality

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 12:29 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.