I want to send outlook email from excel.
I need to insert today's date inside the HTML code.
"strDate" in the email body does not work when trying to format the date.
I tried replace function, Format (Date) and other ways.
Sub SharePerformance1()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xOutMsg As String
Dim strDate As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
strDate = Format(Date, "dd mmm yyyy")
xOutMsg = "Good morning!<br />This pay period is from <b><span style=""color:#CE0426"">&strDate&</span style=""color:#CE0426""></b>To help ensure you are paid accurately and timely, please follow the instructions below.<br /><br />" & _
"<u>Salaried team members</u><br />" & _
"<span style=font-size:5px>●</span> Reason e.g. sick, vacation, jury duty<br /><br />" & _
"Thank you!"
With xOutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Notice" & Format(Now() + 1, "dddd, mmmm dd") & " for Pay Period " & Format(Now() - 8, "dd") & "-" & Format(Now() + 3, "dd/yyyy")
.HTMLBody = xOutMsg
.Display
End With
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub

