PDA

View Full Version : [SOLVED:] Store sent emails to selected folder



biko1990
01-29-2019, 03:39 AM
Hi Guys,
I'm new on this forum, i already tried some searching to try if someone asked the same question but didn't succeeded.
I found a macro on the internet which i want to use, the macro pops up a fence, each time i sent an email, in which i can select the folder in which i want to store the email.
on the following location i found the macro:
https://www.datanumen.com/blogs/auto-save-specific-sent-emails-non-default-folder-outlook-vba/

the macro is the following:
Dim desFolder As Folder
If TypeName(Item) = "MailItem" And Item.DeleteAfterSubmit = False Then
'specify the email
If InStr(Item.To, "shirley") > 0 Or InStr(LCase(Item.Subject), "test") > 0 Then
'Display the “Select Folder” dialog box
Set desFolder = Application.Session.PickFolder
Set Item.SaveSentMessageFolder = desFolder
End If
End If
End Sub

Now the problem is the following:
When I write the macro into VBA in Outlook, the macro does not appear in the run/sub user form (F5).
Probably just a small mistake? Is there anyone who knows how to tackle this issue?
Thanks in advance!
Biko

gmayor
01-29-2019, 04:52 AM
You missed the name of the macro which should be as follows

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim desFolder As Folder
If TypeName(Item) = "MailItem" And Item.DeleteAfterSubmit = False Then
'specify the email
If InStr(LCase(Item.To), "shirley") > 0 Or InStr(LCase(Item.Subject), "test") > 0 Then
'Display the “Select Folder” dialog box
Set desFolder = Application.Session.PickFolder
Set Item.SaveSentMessageFolder = desFolder
End If
End If
End Sub
The macro goes in the ThisOutlookSession module and it intercepts the send command to file the message in the selected folder. It will not appear in the list of macros because of the callback to Item in the bracketed area of the macro name.

biko1990
01-29-2019, 05:05 AM
Dear Gmayor,

I changed the macro with the name.
now still nothing happens when click on send email..
23655

gmayor
01-29-2019, 05:09 AM
It works as intended here. Does the message you are sending meet the criteria set in the macro? Do you have Outlook security set to prevent macros from running?

biko1990
01-29-2019, 05:33 AM
My outlook security settings are set as following
23656

According to the message if it is according criteria i'm not sure.
Are there any special criteria written?

biko1990
01-29-2019, 06:06 AM
The only thing i can find is that item.to >0 and item.subject >0

it just worked only once.. don't know what i did different, but after a cancelled, outlook crashed.

biko1990
01-29-2019, 06:15 AM
Just found another code on the internet that does work!
Thanks for the support!

www.outlookcode.com/d/code/setsavefolder.htm