Consulting

Results 1 to 7 of 7

Thread: Store sent emails to selected folder

  1. #1
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    5
    Location

    Store sent emails to selected folder

    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...r-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

  2. #2
    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.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    5
    Location
    Dear Gmayor,

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

  4. #4
    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?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    5
    Location
    My outlook security settings are set as following
    macro1.jpg

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

  6. #6
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    5
    Location
    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.

  7. #7
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    5
    Location
    Just found another code on the internet that does work!
    Thanks for the support!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •