Home » excel » html – Set a web link to a "word" in a VBA email

html – Set a web link to a "word" in a VBA email

Posted by: admin May 14, 2020 Leave a comment

Questions:

If this email does not display properly, please click here.

I would like to be able to have the person in the email click on the word “here” and then it will take them to a website.

This is what I have bee using but it just puts the full link into the email.

mymsg = "<HTML><BODY>"
mymsg = "If this email does not display properly, please click " & "<A href=http://us.localnews.com/ov?mailing=3TVGZMLJ-WDS49&m2u=3TVGZMLK-3TVGZMLJ-12Z630I>URL Text</A>"
mymsg = mymsg & "</BODY></HYML>"
How to&Answers:

Keep it simple, no need for the HTML/BODY tags

Example

Option Explicit
Public Sub Example()
    Dim OutApp As Object
    Set OutApp = CreateObject("Outlook.Application")

    Dim OutMail As Object
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
        .HTMLBody = "If this email does not display properly, please click " & _
                    "<A href=https://stackoverflow.com/>" & _
                    "Here</A>"
        .Display
    End With

End Sub

Make sure you are using HTMLBody Property

MSDN – HTMLBody Property

Returns or sets a String representing the HTML body of the specified item. The HTMLBody property should be an HTML syntax string. Read/write.