September 1, 2021
I am having trouble figuring out the code needed to highlight the DateDue Object in my e-mail body and I'm wondering if anyone here can help point me in the right direction.
Currently, I have a For Each Loop set up to run an If Then Statement and send an e-mail out to the recipients for any items that are have upcoming due dates (as specified in the If Then). The loop, itself, works great. It's pulling the correct items and the e-mail populates with all the correct information.
My problem is, I want to highlight the due date within the e-mail, but because it is set as a Range, I'm not able to use the typical html formatting. The html code has worked for all the other pieces of text within the e-mail, but not the due date.
At the beginning of the sub, I declared the DueDate as a Range and set the Range to the corresponding cells in the worksheet (M3:M26). I've also provided the code as it's currently written below and attached the file I'm working with.
Dim emailApplication As Object
Dim emailItem As Object
Dim DateDueCol As Range
Dim DateDue As Range
Set DateDueCol = Range("M3:M26") 'the range of the cells that contain your due dates
Set emailApplication = CreateObject("Outlook.Application")
For Each DateDue In DateDueCol
Set emailItem = emailApplication.CreateItem(0)
If DateDue <> "" And DateDue <= Range("T2") + Range("T1") Then
emailItem.to = Range("V6").Value & "; " & Range("V7").Value
emailItem.CC = Range("V5").Value & "; " & Range("V8").Value
emailItem.Subject = "Reefer Service Scheduling Reminder"
emailItem.body = "Hello " & Range("S6") & " and " & Range("S7") & "," & vbNewLine & vbNewLine & "This is a reminder that the Reefer Service for Trailer " & DateDue.Offset(0, -11) & " is due on " & DateDue & ". Please schedule a service for this trailer." & vbNewLine & "Thank you!"
MsgBox ("Service E-mail Reminders have been sent")
The blue text above (DateDue) is the information I'd like to have highlighted.
Any guidance here would be greatly appreciated!
November 8, 2013
Instead of .Body, you can use .HTMLBody, then you'll be able to use HTML markup:
here is a link with an example:
You might also need to use:
Format(DueDate,"mmm, dd yyyy")
September 1, 2021