September 1, 2021
Hi Guys,
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.
Sub ServiceEmailReminder()
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!"
emailItem.Display
End If
Next DateDue
MsgBox ("Service E-mail Reminders have been sent")
End Sub
The blue text above (DateDue) is the information I'd like to have highlighted.
Any guidance here would be greatly appreciated!
Thank you,
Amanda
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Hi,
Instead of .Body, you can use .HTMLBody, then you'll be able to use HTML markup:
here is a link with an example:
https://www.myonlinetraininghu.....con#p16812
You might also need to use:
Format(DueDate,"mmm, dd yyyy")
Answers Post
1 Guest(s)