Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2021, 04:17 AM
RichCowell RichCowell is offline Outlook VBS - Automatically delay sending evening & weekend emails until 0700 the following weekday Windows 10 Outlook VBS - Automatically delay sending evening & weekend emails until 0700 the following weekday Office 2019
Novice
Outlook VBS - Automatically delay sending evening & weekend emails until 0700 the following weekday
 
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
Reply

Tags
vbs

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delay in Outlook sending emails RobertWA Outlook 0 06-03-2020 06:36 AM
Sending e-mail with delay paik1002 Outlook 1 02-29-2016 11:27 AM
Long delay in sending emails in Outlook 2007 GeeJay Outlook 4 10-04-2013 07:41 AM
delay sending email and follow up on all emails lefteris Outlook 1 05-17-2011 05:11 PM
How to delay sending an invitation... imported_misterbobthetomato Outlook 0 07-20-2006 07:42 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft