Steve Wood
New Member
- Outlook version
- Outlook 2016 64 bit
- Email Account
- IMAP
Hello All -
I found the below code online that delays delivery to the next business day automatically if sent at night or over the weekend. It is just what I was looking for as I send a lot of business mail in the evenings and weekends and I don't want the mail to interrupt my coworkers off-time. The only problem is that, sometime I do want an email to go out immediately and it doesn't seem like there is an easy way to override the macro. I would love this if when I sent a email after hours a simple pop-up window opened and asked if I wanted to delay delivery. I don't want it any more complex than I could answer with one simple key stroke. ENTER to send on the next business day. I'm not a programmer and know just enough to copy and paste the code into the VBA window. I would be very grateful if someone could tell how to change the code to add this feature. Thanks in advance for any assistance you con provide! Regards...Steve
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 (Weekday Function (Visual Basic)
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
Else
3: objMailItem.DeferredDeliveryTime = DateAdd("n", 30, Now) 'Else delay is + 30 minutes
End If
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
Else
6: objMailItem.DeferredDeliveryTime = DateAdd("n", 30, Now) 'Else delay is + 30 minutes
End If
Exit Sub
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 " & _
Err.Number)
End Sub
I found the below code online that delays delivery to the next business day automatically if sent at night or over the weekend. It is just what I was looking for as I send a lot of business mail in the evenings and weekends and I don't want the mail to interrupt my coworkers off-time. The only problem is that, sometime I do want an email to go out immediately and it doesn't seem like there is an easy way to override the macro. I would love this if when I sent a email after hours a simple pop-up window opened and asked if I wanted to delay delivery. I don't want it any more complex than I could answer with one simple key stroke. ENTER to send on the next business day. I'm not a programmer and know just enough to copy and paste the code into the VBA window. I would be very grateful if someone could tell how to change the code to add this feature. Thanks in advance for any assistance you con provide! Regards...Steve
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 (Weekday Function (Visual Basic)
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
Else
3: objMailItem.DeferredDeliveryTime = DateAdd("n", 30, Now) 'Else delay is + 30 minutes
End If
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
Else
6: objMailItem.DeferredDeliveryTime = DateAdd("n", 30, Now) 'Else delay is + 30 minutes
End If
Exit Sub
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 " & _
Err.Number)
End Sub