Pierre Bonaparte
Pierre Bonaparte

Reputation: 633

Writing into new email: change the Date -1 if Date = vbMonday to "text"

I have developed the code which allows me to send an email with predefined text, which I set to change only where the date is Date -1

I need to add another functionality: If the current day is vbMonday insert "weekend" instead of Date - 1

I was thinking about something along the lines of: If Date = vbMonday then instead of Date - 1 enter "weekend"

This is the part:

Sub Email_Outlook()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "Hi," & vbNewLine & vbNewLine & _
              "No events: " & Date - 1 & vbNewLine & vbNewLine & _
              "Thanks" & vbNewLine & vbNewLine & _
              "Thomas"

Thanks

Upvotes: 1

Views: 67

Answers (2)

DisplayName
DisplayName

Reputation: 13386

strbody = "Hi," & vbNewLine & vbNewLine & _
          "No events: " & IIf(Weekday(Date) = vbMonday, "weekend", Date - 1) & vbNewLine & vbNewLine & _
          "Thanks" & vbNewLine & vbNewLine & _
          "Thomas"

Upvotes: 3

Vityata
Vityata

Reputation: 43593

Try like this with the weekdays:

Public Sub TestMe()    
    If Weekday(Date) = vbWednesday Then
        Debug.Print "It is Wednesday!"
    End If    
End Sub

Upvotes: 1

Related Questions