My vba subroutine preformats an email, and then displays the email so the user can modify it. When the user sends the message, I want to log the actual To address. The attached code comes close, but it logs the preformatted To address.
I know I could create my own form that duplicates outlook's email form, but that is not a very clean approach.
I could also search through the Sent Items folders to see if the message was there, but I am worried the folder might not be sorted by date sequence. Plus, the user might have change the subject etc, so the search would not be reliable.
I hope someone can come up with a simpler solution.
Sub sendEmail(strContactEmail, strCc, strEmailBody, strEmailSubject, Optional strEmailAttachments)
Dim olLook, olNewEmail As MailItem
Set olNewEmail = olapp1.CreateItem(0)
With olNewEmail 'Attach template
.To = strContactEmail
.CC = strCc
.Body = strEmailBody
.Subject = strEmailSubject
.Display (True) ' make it modal and wait for user action
On Error Resume Next
Dim wasSent As Boolean
wasSent = olNewEmail.Sent
If Err <> 0 Then wasSent = True
On Error GoTo 0
If wasSent Then
MsgBox "Sent to" & strContactEmail
MsgBox "Email was canceled and will not be logged"