![]() |
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 know this question hass been asked before but I was unable to make it work.
In order to make up for Outlook's inadequate handling of IMAP, I put together a simple macro that would move messages to a folder "Trash" when invoked. (The delete key deletes emails forever - thank you Microsoft!) All I want to do is to enable the macro without having to manually enable it each time I start outlook and without setting my security settings to enable all macros. I would appreciate any help. Here is the code: Sub MoveToTrash() On Error Resume Next Dim objFolder As MAPIFolder Dim objNS As NameSpace, objItem As MailItem Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.Folders("KJB").Folders("Trash") If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.UnRead = False objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objNS = Nothing End Sub |
Ads |
#2
|
|||
|
|||
![]() Either use the settings and enable macros, or sign the VBA project; for that search for 'SelfCert.exe'. -- Best regards Michael Bauer - MVP Outlook : Outlook Categories? Category Manager Is Your Tool : VBOffice Reporter for Data Analysis & Reporting : http://www.vboffice.net/product.html?pub=6&lang=en Am Tue, 15 Sep 2009 23:15:01 -0700 schrieb Keith: I know this question hass been asked before but I was unable to make it work. In order to make up for Outlook's inadequate handling of IMAP, I put together a simple macro that would move messages to a folder "Trash" when invoked. (The delete key deletes emails forever - thank you Microsoft!) All I want to do is to enable the macro without having to manually enable it each time I start outlook and without setting my security settings to enable all macros. I would appreciate any help. Here is the code: Sub MoveToTrash() On Error Resume Next Dim objFolder As MAPIFolder Dim objNS As NameSpace, objItem As MailItem Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.Folders("KJB").Folders("Trash") If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If If Application.ActiveExplorer.Selection.Count = 0 Then Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection If objFolder.DefaultItemType = olMailItem Then If objItem.Class = olMail Then objItem.UnRead = False objItem.Move objFolder End If End If Next Set objItem = Nothing Set objFolder = Nothing Set objNS = Nothing End Sub |
#3
|
|||
|
|||
![]()
Thanks a lot. I didnt find it by that name. Its under MS office and tools
as "Digital Certificate for VBA Projects.lnk". Then i did a Google search and found this great writeup on how to do it, though its pretty self-explanatory: http://www.howto-outlook.com/howto/selfcert.htm Quick follow-up. Is there a way to make the macro run when I hit the delete key? Right now I have an icon for it on my toolbar but sometimes I hit delete and then a message is gone forever. Also, I lifted the code and modified it from a macro someone else wrote so its probably lousy code on my part. Its quite slow - any ideas on how to make it faster? I am not a VBA expert - as you can no doubt tell! Thanks again Michael. |
#4
|
|||
|
|||
![]() Outlook can't tell you what has been pressed on the keyboard. For that you'd have to use a lot of Win32 API code. You might rather want to stick with the toolbar button. But as far as I know the DEL key doesn't delete messages, it just marks them as deleted. Just click Edit/Recover (or similar) , and the messages are back. -- Best regards Michael Bauer - MVP Outlook : Outlook Categories? Category Manager Is Your Tool : VBOffice Reporter for Data Analysis & Reporting : http://www.vboffice.net/product.html?pub=6&lang=en Am Wed, 16 Sep 2009 14:50:02 -0700 schrieb Keith: Thanks a lot. I didnt find it by that name. Its under MS office and tools as "Digital Certificate for VBA Projects.lnk". Then i did a Google search and found this great writeup on how to do it, though its pretty self-explanatory: http://www.howto-outlook.com/howto/selfcert.htm Quick follow-up. Is there a way to make the macro run when I hit the delete key? Right now I have an icon for it on my toolbar but sometimes I hit delete and then a message is gone forever. Also, I lifted the code and modified it from a macro someone else wrote so its probably lousy code on my part. Its quite slow - any ideas on how to make it faster? I am not a VBA expert - as you can no doubt tell! Thanks again Michael. |
#5
|
|||
|
|||
![]()
Thanks Michael,
No, the emails are gone. On other platforms like my iPhone then you can tell it to move deleted items to a selected folder like "Trash" but Outllook just throws them in the bit-bucket. Its really poor design but I think microsoft really only care about exchenge support and they do the bare minimum to support POP and IMAP. There are other posts about how to write vba to do this. Incidentally, can you see if its possible to make this code run faster? don't know enoutgh about VBA to speed it up myself. Keith |
#6
|
|||
|
|||
![]() #1: I'd say it's no IMAP account then; or you have a filter in place that hides those messages that are flagged as deleted. A lot of people here ask for how to delete messages from an IMAP account immediately just by hitting the DEL key, but Outlook doesn't support that. #2: no -- Best regards Michael Bauer - MVP Outlook : Outlook Categories? Category Manager Is Your Tool : VBOffice Reporter for Data Analysis & Reporting : http://www.vboffice.net/product.html?pub=6&lang=en Am Thu, 17 Sep 2009 19:54:01 -0700 schrieb Keith: Thanks Michael, No, the emails are gone. On other platforms like my iPhone then you can tell it to move deleted items to a selected folder like "Trash" but Outllook just throws them in the bit-bucket. Its really poor design but I think microsoft really only care about exchenge support and they do the bare minimum to support POP and IMAP. There are other posts about how to write vba to do this. Incidentally, can you see if its possible to make this code run faster? don't know enoutgh about VBA to speed it up myself. Keith |
#7
|
|||
|
|||
![]()
You've declared objItem as a MailItem type, but then you check if the
class is olMail, isn't that redundant? Also, regardless of whether the Trash folder holds non-MailItems, you can skip the DefaultItemType check. If it does matter, you're already limiting the For loop to mail items anyway, and if it doesn't matter, the check is pointless. You might also consider using the Restrict Method on the Items Collection and returning a filtered subset of items. It can make your code faster if the folder contains a large number of non-MailItems. http://msdn.microsoft.com/en-us/libr...ffice.11).aspx --JP On Sep 17, 10:54*pm, Keith wrote: Thanks Michael, No, the emails are gone. *On other platforms like my iPhone then you can tell it to move deleted items to a selected folder like "Trash" but Outllook just throws them in the bit-bucket. *Its really poor design but I think microsoft really only care about exchenge support and they do the bare minimum to support POP and IMAP. * There are other posts about how to write vba to do this. Incidentally, can you see if its possible to make this code run faster? * don't know enoutgh about VBA to speed it up myself. Keith |
#8
|
|||
|
|||
![]() Skipping the DefaultItemType is a good catch; the check is useless not because of the declaration of the object variable but because it will return the same value in any loop. The Restrict method doesn't help as he loops through a collection of selected items. -- Best regards Michael Bauer - MVP Outlook : Outlook Categories? Category Manager Is Your Tool : VBOffice Reporter for Data Analysis & Reporting : http://www.vboffice.net/product.html?pub=6&lang=en Am Fri, 18 Sep 2009 07:14:22 -0700 (PDT) schrieb JP: You've declared objItem as a MailItem type, but then you check if the class is olMail, isn't that redundant? Also, regardless of whether the Trash folder holds non-MailItems, you can skip the DefaultItemType check. If it does matter, you're already limiting the For loop to mail items anyway, and if it doesn't matter, the check is pointless. You might also consider using the Restrict Method on the Items Collection and returning a filtered subset of items. It can make your code faster if the folder contains a large number of non-MailItems. http://msdn.microsoft.com/en-us/libr...ffice.11).aspx --JP On Sep 17, 10:54*pm, Keith wrote: Thanks Michael, No, the emails are gone. *On other platforms like my iPhone then you can tell it to move deleted items to a selected folder like "Trash" but Outllook just throws them in the bit-bucket. *Its really poor design but I think microsoft really only care about exchenge support and they do the bare minimum to support POP and IMAP. * There are other posts about how to write vba to do this. Incidentally, can you see if its possible to make this code run faster? * don't know enoutgh about VBA to speed it up myself. Keith |
#9
|
|||
|
|||
![]()
Yep it’s definitely IMAP and the messages are definitely deleted from the
server. The account shows as "IMAP/SMTP" in the account settings. Deleted emails from Outlook disappear from my view on the iPhone too. If I delete them from Outlook they are gone forever. If I delete them from my iPhone they go to Trash. I understand though that the function of putting deleted items in a designated folder such as Trash is not part of the IMAP spec but that most IMAP platforms (except Outlook) support it. Outlook does however let me designate a sent items folder. I used to use POP but when I got my iPhone, I switched to IMAP to access my emails because I wanted to synchronize emails between the two platforms. My email account is with GoDaddy so I use: IMAP.secureserver.net and SMTPOUT.secureserver.net. Godaddy uses "Trash" for deleted items. Ive asked about IMAP support in Outlook General section and the result seems to be to write a VBA macro because this delete -move to trash function is not supported. Thanks so much for your help. Keith |
#10
|
|||
|
|||
![]()
Thanks you so much Michael and JP
I made the suggested change (At least I think I did – it still works anyway!) Your input lead me to ask some questions which I have added as comments. I really really appreciate your help. So here is the new code: Sub MoveToTrash() On Error Resume Next Dim objFolder As MAPIFolder Dim objNS As NameSpace Dim objItem As MailItem Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.Folders("KJB").Folders("Trash") ' is this redundant since the folder name is hard coded and doesnt change?? If objFolder Is Nothing Then MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER" End If ' Is this test needed since it appears the FOR loop below takes care of this test If Application.ActiveExplorer.Selection.Count = 0 Then Exit Sub End If For Each objItem In Application.ActiveExplorer.Selection objItem.UnRead = False objItem.Move objFolder Next ' Do these items need to be set to nothing. Wont they be removed from the heap or stack when the sub() ends? Set objItem = Nothing Set objFolder = Nothing Set objNS = Nothing End Sub |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Eliminate need for "Enable Macro" selection | cte67 | Outlook and VBA | 7 | August 21st 09 06:30 PM |
eliminate error message "Borlane Database Engine not installed" | Outlook 2007 needs help - | Outlook - Installation | 2 | June 5th 08 05:47 PM |
How do I edit "show time as" drop down selection? | DGarton | Outlook - Calandaring | 1 | November 29th 07 10:56 PM |
find/eliminate "active content" in a customized outlook form | TomS | Outlook - Using Forms | 1 | August 3rd 07 03:54 PM |
how to delete email address from "to" button selection | Buckskin | Outlook - Using Contacts | 2 | June 11th 07 11:56 PM |