Highlight Text in VBA HTML

stu_c

Registered User.
Local time
Today, 21:59
Joined
Sep 20, 2007
Messages
493
Hi All
I have VBA HTML code to work so it transfers everything from a form into an Email have managed to get bold to work but I ideally want some text to be highlighted in either red or yellow, I have tried
<mark> and <BGcolor> but haveing some issues

Code:
sBody = sBody & "<B><mark>Highlight</mark></B>"
 
try:
Code:
sBody = sBody & "<B><span style='color:red;'>Highlight</span></B>"
 
You need to use the correct HTML formatting codes - something like

<body><font color=#ff0000>"
 
The other option would to for it to open a Email template using

Code:
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("\\TemplateEmail.oft")
MyItem.Subject = "Status Report"

MyItem.display

and input into certain bookmark points but not entirely sure the code on how to do this?
 
Code:
Dim myOlApp, myItem
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItemFromTemplate("\\TemplateEmail.oft")
With myItem
    .Subject = "Status Report"
    .HTMLBody = Replace$(.HTMLBody, "Highlight", "<B><span style='color:red;'>Highlight</span></B>")
    .Display
End With
 
Did you try adjusting for yourself?
Code:
sBody = sBody & "<B><span style='background-color:red;'>Highlight</span></B>"
 
Code:
<div><font color=red style="BACKGROUND-COLOR:#FFFF00">RED text with yellow highlighting</font></div>

1706623201724.png
 
All the examples in that screenshot were created using Access rich text which is of course a subset of HTML.
Not all the features of rich text are included in the latest versions of HTML but you can guarantee that code will work in Access.
The converse isn't necessarily true.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom