RichCowell
Board Regular
- Joined
- Dec 5, 2013
- Messages
- 121
- Office Version
- 365
- Platform
- Windows
Hi all,
I've got a script for Outlook that *should* delay sending emails Mon-Fri after 1800, and any time at the weekend, until 0700 the next weekday morning.
It seems to work Mon-Thu, but Fri-Sat it just sends it the following morning rather than waiting until Monday morning.
Can anyone help identify/correct the issues? I'm a complete novice with VBS & Outlook, but I'm trying to promote mental health and wellbeing, and trying to minimise the work I put on others outside working hours.
Thanks,
Rick
I've got a script for Outlook that *should* delay sending emails Mon-Fri after 1800, and any time at the weekend, until 0700 the next weekday morning.
It seems to work Mon-Thu, but Fri-Sat it just sends it the following morning rather than waiting until Monday morning.
Can anyone help identify/correct the issues? I'm a complete novice with VBS & Outlook, but I'm trying to promote mental health and wellbeing, and trying to minimise the work I put on others outside working hours.
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim dayname As String
' If after 6PM
If Now() > DateSerial(Year(Now), Month(Now), Day(Now)) + #5:59:00 PM# Then
sendat = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM#
' If before 7AM
ElseIf Now() < DateSerial(Year(Now), Month(Now), Day(Now)) + #6:59:00 AM# Then
sendat = DateSerial(Year(Now), Month(Now), Day(Now)) + #7:00:00 AM#
' We'll test the date of all messages
ElseIf WeekdayName(Weekday(Now())) = "Saturday" Or WeekdayName(Weekday(Now())) = "Sunday" Then
' this will be changed by the next part if a weekend
sendat = DateSerial(Year(Now), Month(Now), Day(Now)) + #11:00:00 PM#
End If
dayname = WeekdayName(Weekday(sendat))
Select Case dayname
Case "Saturday"
sendat = DateSerial(Year(Now), Month(Now), Day(Now) + 2) + #7:00:00 AM#
Case "Sunday"
sendat = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM#
End Select
Item.DeferredDeliveryTime = sendat
Debug.Print Now(), dayname, sendat
End Sub
Thanks,
Rick