question

PatrickDegenaar-1654 avatar image
0 Votes"
PatrickDegenaar-1654 asked JadeLiang-MSFT commented

Outlook defer weekend emails macro - Outlook thinks Sunday is Monday

Hi,

I've been trying to create a Macro to defer weekend emails to the following Monday morning. Once I have a fully working code, I want to roll it out to my wider team so that people have time to relax and think over weekends

I have code that sort of works, but Outlook seems to think that Saturday is Sunday, and Sunday is Monday. A workaround is to simply define the day that seems to work. But I don't know if this is going to work with the rest of the team. Is there any way to fix this?

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

' ====================================================================================
' Weekends:
' Do not send emails until Monday morning
' If the email has been flagged as "high importance", then it will still be sent
' ====================================================================================

 ' Check if it is a Satuday - if so defer email to Monday unless "high importance"
 ' Note for some stupid reason, My Outlook thinks "Sunday" = Saturday - Why???
 If WeekdayName(Weekday(Now())) = "Sunday" Then
     ' Check if the email is high importance
     If Item.Importance = 2 Then
         'Do nothing - i.e. let the email be sent
     Else
         ' Delay the email to monday morning 7am
         sendat = DateSerial(Year(Now), Month(Now), Day(Now) + 2) + #7:00:00 AM#
     End If

 ' Check if it is a saturday - if so defer email to Monday unless "high importance"
 ' Note for some stupid reason, My Outlook thinks "Monday" = Sunday - Why???
 ElseIf WeekdayName(Weekday(Now())) = "Monday" Then
     ' Check if the email is high importance
     If Item.Importance = 2 Then
         'Do nothing - i.e. let the email be sent
     Else
         ' Delay the email to monday morning 7am
         sendat = DateSerial(Year(Now), Month(Now), Day(Now) + 1) + #7:00:00 AM#
     End If

 Item.DeferredDeliveryTime = sendat

End Sub


office-outlook-itprooffice-vba-devoffice-addins-dev
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PatrickDegenaar-1654 ,

Please kindly understand under Outlook tag, we mainly focus on general issues on Outlook desktop client. Considering that your issue may be more related to Outlook development, I would add office-addins-dev, office-vba-dev tag under your post to solve it better. Thanks for your understanding.

0 Votes 0 ·

0 Answers