Creating formatted Outlook Msg from VBA

  • Thread starter Thread starter BillW
  • Start date Start date
B

BillW

Hi,

Is there a way to create e-mail messages in Outlook via
Excel VBA with formatted (i.e. bold, colored) text. I am
currently passing in the string "MailBody" to Outlook
using the following code. This code inserts an unformatted
text string?

Dim OklApp As New Outlook.Application
Dim OutLk As Outlook.MailItem

Set OutLk = OklApp.CreateItem(olMailItem)
OutLk.Body = MailBody

Is there any way I can insert formatted text?

Thanks,

Bill W.
 
Bill,

If you use the htmlbody property you can insert normal html formatting
codes. You need a reference in the project to Outlook.

eg.

Sub TestEmail()

Dim olApp As Outlook.Application
Dim olMail As MailItem
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail

.To = "(e-mail address removed)"
.Subject = "test format"
.HTMLBody = "<B>Hello</B>" & chr(34) & "Goodbye"

..Send

End With
Set olMail = Nothing
Set olApp = Nothing
End Sub

Robin Hammond
www.enhanceddatasystems.com
 
Back
Top