• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Convert plain text email to HTML

Maggieh

New Member
Hello. I have created a macro to send an email with data from a worksheet. It works fine as plain text but I would like to format (ie bold) the dollar value in (I40) and date value in (I21) which means I need to convert it to HTML. Everything I've tried has failed. Can you please help? This is my code.

>>> use code - tags <<<
Code:
Private Sub CommandButton4_Click()
Dim xOutApp As Object
    Dim xOutMail As Object
    Dim objFileSystem As Object
    Dim strTempFile As String
    'Dim myAttachments As Object
    Dim xMailBody As String
       
    On Error Resume Next
    Set xOutApp = CreateObject("Outlook.Application")
    Set xOutMail = xOutApp.CreateItem(0)
   
   
    xMailBody = "Hello " & Range("O3") & vbNewLine & vbNewLine & _
              "Thank you for providing your documentation." & vbNewLine & vbNewLine & _
               "As a result of our review we can confirm that you were impacted by some of the issues and are now owed a gross payment of " & Format(Range("I40"), "Currency") & "." & vbNewLine & _
              "This payment will be made to your nominated bank account on " & Range("I21") & "." & vbNewLine & vbNewLine & _
            "If you have any further questions please refer to the information on our website." & vbNewLine & vbNewLine & _
            "Thank you" & vbNewLine
           
    With xOutMail
        .SentOnBehalfOfName = """Project"" <email@email>"
        .To = Range("T1")
        .CC = ""
        .BCC = ""
        .Subject = Range("O1")
        .Body = xMailBody
       
        .Send   'or use .Display
    End With
    On Error GoTo 0
    Set xOutMail = Nothing
    Set xOutApp = Nothing

End Sub
 
Last edited by a moderator:
.
Here is a sample file to review :

Code:
Option Explicit

Sub EmailSend()
Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody1 As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

strbody1 = "<B><U>AN AUDIT HAS BEEN SUBMITTED IN YOUR NAME FOR THE BELOW BOOKING:</B></U>"

    On Error Resume Next
    With OutMail
        .to = Range("AuditEmailTO").Value
        .CC = Range("AuditEmailCC").Value
        .BCC = Range("AuditEmailBCC").Value
        .Subject = "AUDIT SUBMITTED: " & Range("AuditResponsible").Value
        .HTMLBody = strbody1
        .Display
        '.Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Back
Top