Outlook - Sent Not in Sent Folder After VBA Sent

User avatar
delaing
3StarLounger
Posts: 242
Joined: 16 Nov 2016, 14:30
Location: Texas

Outlook - Sent Not in Sent Folder After VBA Sent

Post by delaing »

I'm using this scavenged code to select and direct which folder to put a copy of the sent message into, but it is bypassing the usual saving of a copy of the sent message in the standard Sent folder.
I indeed have the Option to save a copy to Sent enabled.
Also, if I Cancel the PickFoder dialog to not copy to a specific folder, then a copy will save to the Sent folder as usual.

What needs to be added or changed so that a copy of the sent message shows in the Sent folder with all data elements intact (date time sent, etc.)?

Code: Select all

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

  If TypeOf Item Is Outlook.MailItem Then
    SaveSentMail Item
  End If
  
End Sub

Private Sub SaveSentMail(Item As Outlook.MailItem)
  Dim F As Outlook.MAPIFolder

  If Item.DeleteAfterSubmit = False Then
    Set F = Application.Session.PickFolder
    If Not F Is Nothing Then
      Set Item.SaveSentMessageFolder = F
    End If
  End If
  
End Sub
Thanks in advance,
Delain
I say this optimistically . . . One day I'll understand it.
But today is not that day!

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Outlook - Sent Not in Sent Folder After VBA Sent

Post by HansV »

Change SaveSentMail as follows:

Code: Select all

Private Sub SaveSentMail(Item As Outlook.MailItem)
  Dim F As Outlook.MAPIFolder
  Dim mi As MailItem

  If Item.DeleteAfterSubmit = False Then
    Set F = Application.Session.PickFolder
    If Not F Is Nothing Then
      Set mi = Item.Copy
      mi.Move F
    End If
  End If
End Sub
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Outlook - Sent Not in Sent Folder After VBA Sent

Post by HansV »

By the way, I have moved this thread from the Other Office Applications forum to the Outlook forum.
Best wishes,
Hans

User avatar
delaing
3StarLounger
Posts: 242
Joined: 16 Nov 2016, 14:30
Location: Texas

Re: Outlook - Sent Not in Sent Folder After VBA Sent

Post by delaing »

Thank you for your response on this.
Is there a way to have it working, as the unmodified version was, by copying(?) the sent message to the selected folder and the message not showing as unRead (along with a version in the Sent folder)?
Now, a copy shows in the selected folder as unRead and there is no header info for the From field. The message in the Sent folder is as you would expect.
sent folder1.png
Can we have two Item.SaveSentMessageFolder destinations?

Thank you,
Delain
You do not have the required permissions to view the files attached to this post.
I say this optimistically . . . One day I'll understand it.
But today is not that day!

User avatar
HansV
Administrator
Posts: 78455
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Outlook - Sent Not in Sent Folder After VBA Sent

Post by HansV »

The copied item hasn't actually been sent. As far as I know there is no event that fires AFTER an item has been sent.
You could mark it as read by inserting the line

Code: Select all

      mi.UnRead = False
below the line Set mi = Item.Copy.
Best wishes,
Hans