E-mail VBA code

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

mpaculea

Thread Starter
Joined
Jan 29, 2015
Messages
1
Hello, I use this code designed by one member of this forum named XCubed the only problem I have is that I would like to have more font formating options to the email body to create a more complex email body.

What I would exactly like is an option to let me add HTML Tags, <b> , </br> , <p> and other tags.

If its not possible atleast I would like the option to bold a part of the text lets say to bold the "Please update" and to add a background color to the word "Please"

Thank you very much and I hope i was clear enough.

Code:
Sub eMail()
Dim lRow As Integer
Dim i As Integer
Dim toDate As Date
Dim toList As String
Dim eSubject As String
Dim eBody As String

With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
End With

Sheets(1).Select
lRow = Cells(Rows.Count, 4).End(xlUp).Row

For i = 2 To lRow
toDate = Replace(Cells(i, 3), ".", "/")
  If Left(Cells(i, 5), 4) <> "Mail" And toDate - Date <= 7 Then
     Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)

        toList = Cells(i, 4)    'gets the recipient from col D
        eSubject = "Project " & Cells(i, 2) & " is due on " & Cells(i, 3)
        eBody = "Dear " & Cells(i, 1) "Please update your project status."
        
        On Error Resume Next
        With OutMail
        .To = toList
        .CC = ""
        .BCC = ""
        .Subject = eSubject
        .Body = eBody
        .bodyformat = 1
        .Display   ' ********* Creates draft emails. Comment this out when you are ready
        '.Send     '********** UN-comment this when you  are ready to go live
        End With
 
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
 Cells(i, 5) = "Mail Sent " & Date + Time 'Marks the row as "email sent in Column A"
End If
Next i

ActiveWorkbook.Save

With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
End With
End Sub
 
Joined
Sep 4, 2003
Messages
4,916
You just need to format the body as "olFormatHTML" and then compose the olEmail.HTMLBody to include your actual text along with the HTML tags. See my example below

Code:
Dim olApp As Outlook.Application

Dim olEmail As Outlook.MailItem

 

Set olApp = New Outlook.Application

Set olEmail = olApp.CreateItem(olMailItem)

 

olEmail.BodyFormat = olFormatHTML

olEmail.HTMLBody = "<font face='comic sans ms' color='red'>THIS IS A TEST</font>"

olEmail.Display
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top