My ultimate goal is to find a way to flag an email I am about to send with a reminder for both the person I am sending the email to and myself at today's date and time plus x amount of days. I've been able to do this when generating new mail items from Excel for years. The problem I'm having is doing this with a current item in Outlook 2016.
From Excel, I flag the email for followup by recipients and then just BCC myself. When the email is sent, it bounces back to me and I get the reminder because I am a recipient.
My first approach with Outlook VBA was to tag the email with a reminder for myself and also a category. The problem I had was, once the email was sent, it would remove the reminder for myself, but not the recipients. The category would still be attached though. So I decided to switch up and try the method I've been using with Excel.
Everything in this code works great. The email address is attaching, all of the prompts before are working, the reminder date is right. All working except for one thing. My email address in the BBC line is not resolving or not resolving quick enough, I'm not sure. The error message reads: "The operation failed. The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook. Cannot resolve recipient."
Anyone know whats going on or if there is a way to force Outlook to resolve this email address before sending?
Private Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)
Dim response As Integer
Dim DaysToRemind As Byte
response = MsgBox("Would you like to delay send this email?", vbYesNo)
On Error GoTo Skip
If response = vbYes Then olItem.DeferredDeliveryTime = Format(Date, "m/d/yyyy") & " 4:00:00 PM"
On Error GoTo Skip
If response = vbNo Then olItem.DeferredDeliveryTime = Now() - 1
prompt$ = "Do you want to flag this message for followup?"
If MsgBox(prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?") = vbYes Then
DaysToRemind = InputBox("How many days to remind?", "Days Till Reminder", 3)
With olItem
.FlagStatus = olFlagMarked
.FlagRequest = "Follow Up"
.FlagDueBy = Now + DaysToRemind
.Categories = "Waiting on Response"
.BCC = "[email protected]"
'.Save
.Send
End With
End If
Skip:
End Sub
After some tooling with this, I had to end up setting up a rule to do everything I wanted to do, but it gets me to what I want essentially.
Private Sub Application_ItemSend(ByVal olItem As Object, Cancel As Boolean)
Dim response As Integer
Dim DaysToRemind As Byte
response = MsgBox("Would you like to delay send this email?", vbYesNo)
On Error GoTo Skip
If response = vbYes Then olItem.DeferredDeliveryTime = Format(Date, "m/d/yyyy") & " 4:00:00 PM"
On Error GoTo Skip
If response = vbNo Then olItem.DeferredDeliveryTime = Now() - 1
Des = MsgBox("Do you want to flag this message for followup?", vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Add flag?")
If Des = vbYes Then
DaysToRemind = InputBox("How many days to remind?", "Days Till Reminder", 3)
With olItem
.FlagStatus = olFlagMarked
.FlagRequest = "Follow Up"
.FlagDueBy = Now + DaysToRemind
If Right(.Subject, 4) <> " (T)" Then .Subject = .Subject & " (T)"
Set myEmail = .recipients.Add("[email protected]")
myEmail.Type = olBCC
myEmail.Resolve
.Save
End With
End If
If Des = vbNo Then
If Right(olItem.Subject, 4) = " (T)" Then olItem.Subject = Left(olItem.Subject, Len(olItem.Subject) - 4)
End If
Skip:
End Sub
Thanks all
You should not be calling
MailItem.Send
in theApplication.ItemSend
event handler that processes that very item. Just let Outlook proceed with the default behavior.You should also not replace all BCC recipients by setting the BCC property: call
MailItem.Recipients.Add
and set theRecipient.Type
property toolBCC