So today I was approached by an internet friend of mine Richard Tubb, he had a bit of a challenge for me. As a keen Ms Outlook user, he wanted to see if there was a way of delaying all emails that he’d composed and hit send on during the weekend to arrive on the next working day.
Of course, Ms Outlook has the built in deferred delivery time function.. However, setting that manually each time could easily become a bind. So that’s where this little Outlook VBA Snippet steps it.
The code checks to see if today is a weekday upon sending the email, and if it is either a Saturday or Sunday, it then finds the date of the next Monday, and sets the deferred send option to that Monday at 7AM. Of course, should Richard be sending mail through the week, Outlook will simply ignore the code. Simple really
EDIT: So Richard came back to me with a second request, to delay mail sent on a weekday by 30 minutes, I have now adjusted the code to suit.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
On Error GoTo ErrHand 'Error Handling
Dim nxtMonday As String 'Variable containing next Monday's date
Dim objMailItem As MailItem 'Object to hold mail item
Set objMailItem = Item 'Set object to mail item just sent
If Weekday(Date, vbMonday) = 6 Then 'Check to see if todays weekday value is 6 (http://msdn.microsoft.com/en-us/library/82yfs2zh(v=vs.80).aspx)
1: nxtMonday = Date + (2) 'As today is saturday, Monday is today + 2 days
2: objMailItem.DeferredDeliveryTime = nxtMonday & " 08:00:00" 'Set delayed delivery time to today + 2 days
3: objMailItem.DeferredDeliveryTime = DateAdd("n", 30, Now) 'Else delay is + 30 minutes
If Weekday(Date, vbMonday) = 7 Then 'Check to see if todays weekday value is 7
4: nxtMonday = Date + (1) 'As today is Sunday, Monday is today + 1 day
5: objMailItem.DeferredDeliveryTime = nxtMonday & " 08:00:00" 'Set delayed delivery time to today + 1 day
6: objMailItem.DeferredDeliveryTime = DateAdd("n", 30, Now) 'Else delay is + 30 minutes
ErrHand: 'Due to lack of concentration of the code writing genius there has been a bit of an error,
'Lets tell someone about it by popping up a message box with a detailed description on the screen
MsgBox ("An error has occured on line " & Erl & ", with a description: " & Err.Description & ", and an error number " & _
If you find this code useful, or think you have a better way of doing this, drop me a line in the comments below!