View Single Post
 
Old 11-28-2021, 04:17 AM
RichCowell RichCowell is offline Windows 10 Office 2019
Novice
 
Join Date: Nov 2021
Posts: 1
RichCowell is on a distinguished road
Question Outlook VBS - Automatically delay sending evening & weekend emails until 0700 the following weekday

Good morning all,

First time posting here, but visited many times and found solutions.

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
Reply With Quote