I wanted essentially the same solution as you and had some trouble with that macro as well. I searched a couple other sites and eventually found this solution that got me most of the way there. I revised their macro a bit to end up with the code below. I only added a button to run the macro on the Quick access toolbar for New Messages and haven't tested the original code's error handling so I can't vouch for that, but left it in.
Things I changed from the original:
- Changed the comparison with the NoDeferredDelivery default time to
be not equal since I only want to remove the delay if a delay is
already set.
- Added an Exit Sub to that If block since otherwise it would continue on and put the delay in anyway.
- Revised the date calculation logic so that my default send time is 7:38 AM the next morning if it is Sun-Thurs, then Monday morning if it is Friday or Saturday.
- Updated the message box that tells you the new send time to include the day of the week so it would be clear if you ran it on a Friday or Saturday that it would go to Monday instead of tomorrow morning.
Sub DelaySendMail()
On Error GoTo ErrHand ' Error Handling
Dim objMailItem As MailItem ' Object to hold mail item
Dim SendDate As String ' The date to send delayed mail
Dim SendTime As String ' The time to send delayed mail
Dim MailIsDelayed As Boolean ' Set if the mail will be delayed
Dim NoDeferredDelivery As String ' Value if deferred delivery is disabled
SendTime = " 07:38:00" ' Time to deliver delayed mail (7:38 AM)
MailIsDelayed = False ' We assume it's being delivered now
NoDeferredDelivery = "1/1/4501" ' Magic number Outlook uses for "delay mail box isn't checked"
'Set object to mail item you have open
Set objMailItem = Outlook.ActiveInspector.CurrentItem
' Check and make sure current item is an unsent message
If objMailItem.Sent = True Then
Err.Raise 9000
End If
' If mail is currently delayed, remove the delay and quit
If objMailItem.DeferredDeliveryTime NoDeferredDelivery Then 'Altered since test wasn't working in original
objMailItem.DeferredDeliveryTime = NoDeferredDelivery
MsgBox "Mail will be delivered immediately when sent", _
vbOKOnly, "Deferred delivery removed"
Exit Sub 'Added since otherwise it didn't actually quit the method
End If
' Set the date appropriately for the next weekday
If Weekday(Date, vbMonday) = 5 Then
' Today is Friday
' Delay mail three days
SendDate = Date + (3)
MailIsDelayed = True
ElseIf Weekday(Date, vbMonday) = 6 Then
' Today is Saturday
' Delay mail two days
SendDate = Date + (2)
MailIsDelayed = True
Else
' Today is Sunday-Thursday so delay till tomorrow morning
SendDate = Date + (1)
MailIsDelayed = True
End If
If MailIsDelayed Then
' Mail should be delayed - set the delivery date/time
objMailItem.DeferredDeliveryTime = SendDate & SendTime
'Altered to include day it would be sent for visiblity over a weekend
MsgBox "Mail will be delivered on " & _
WeekdayName(Weekday(SendDate)) & ", " & SendDate & " at" & SendTime, _
vbOKOnly, "Mail delayed"
End If
Exit Sub
ErrHand:
' Handle well-known errors with message
' Other errors, just tell the user
If Err.Number = 13 Then
' No current item or current item isn't a mail message
MsgBox "Future delivery can only be set on mail items", vbOKOnly, "Not a mail item"
ElseIf Err.Number = 9000 Then
' The active message has already been sent
MsgBox "Please run this macro from an unsent mail item", vbOKOnly, "Not an unsent mail item"
Else
MsgBox "An error has occured on line " & Erl & _
", with a description: " & Err.Description & _
", and an error number " & Err.Number
End If
End Sub</code></pre>