Outlook defer weekend emails macro - Outlook thinks Sunday is Monday

Patrick Degenaar 1 Reputation point
2021-07-04T07:06:22.103+00:00

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 Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,508 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,900 questions
{count} votes