• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Highlight Text in an Auto E-mail Loop|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Highlight Text in an Auto E-mail Loop|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosHighlight Text in an Auto E-mail Lo…
sp_PrintTopic sp_TopicIcon
Highlight Text in an Auto E-mail Loop
Avatar
Amanda Beyer
Member
Members
Level 0
Forum Posts: 11
Member Since:
September 1, 2021
sp_UserOfflineSmall Offline
1
February 17, 2022 - 5:29 am
sp_Permalink sp_Print

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

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
February 17, 2022 - 4:14 pm
sp_Permalink sp_Print

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")

sp_AnswersTopicAnswer
Answers Post
Avatar
Amanda Beyer
Member
Members
Level 0
Forum Posts: 11
Member Since:
September 1, 2021
sp_UserOfflineSmall Offline
3
February 18, 2022 - 12:11 am
sp_Permalink sp_Print sp_EditHistory

Thank you for your response, Catalin!

Using Format in connection with .HTMLbody was exactly what was needed to execute the code correctly! Thank you very much for your time and help!

Warm Regards,

Amanda

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Saliha Mohamed, David Eva
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
Ashley Hughes
Herbie Key
Trevor Pindling
Stevan Kanjo
Erin Sheldon
Nikita Bhatia
Sheilah Taylor
Clare Webber
David Jenssen
Dominic Brosnahan
Forum Stats:
Groups: 3
Forums: 24
Topics: 6526
Posts: 28576

 

Member Stats:
Guest Posters: 49
Members: 32810
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.