Search code examples
excelvbahtml-email

How to Edit Font Colour of Hyperlink in Email?


I am using an Outlook Email Template wherein I find a specific text and then replace it into a Embedded Hyperlink, and then the email is sent out. However when the email is sent out the font color for the hyperlink becomes blue by default.

How can I set a font color (Black or White) that remains when the email goes out.

Sub Mail_Merge()
    Tme1 = Now()

    Application.ScreenUpdating = False
    On Error GoTo C:
    Dim oApp As Object, oMail As Object

    Set oApp = CreateObject("Outlook.Application")
    a = Sheet1.Range("B1048576").End(xlUp).Row

    For i = 2 To a

    Set oMail = oApp.CreateItemFromTemplate(Cells(i, 10))
    With oMail

    .To = Cells(i, 2)
    .Subject = Cells(i, 8)

    strfind = "X1X1X1"
    strLink = Cells(i, 3)
    strLinkText = Cells(i, 9)
    strNewText = "<a href=" & Chr(34) & strLink & Chr(34) & ">" & strLinkText & "</a>"
    .HTMLBody = Replace(.HTMLBody, strfind, strNewText, 1, 1, vbTextCompare)
    
    .Display

    .send
    End With
    Cells(i, 1) = "Mail sent successfully"
    Next i
    C:
    Application.ScreenUpdating = True

    tme2 = Now() - Tme1
    Application.StatusBar = Format(tme2, "h:mm:SS")
End Sub

Solution

  • You can use inline CSS:

    strNewText = "<a style='color:#F00;' href='" & strLink & "'>" & strLinkText & "</a>"