Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding hyperlinks to excel email body text

Tags:

excel

vba

I am trying to generate emails from excel but want to add hyperlinks to the email body text. I want the hyperlinks to show as text and not the file paths.

How would I go about doing this?

I am using the below code.

    strBody = "Hello " & Range("QuoteFirstName").Value & "," & _
       vbNewLine & _
       vbNewLine & _
           "It was good to speak with you earlier today/yesterday." & _
       vbNewLine & _
       vbNewLine & _
           "[Any personal message]" & _
       vbNewLine & _
       vbNewLine


On Error Resume Next
With OutMail
    .To = StrTo
    .CC = ""
    .BCC = ""
    .Subject = StrSubject
    .Body = StrBody
    .Attachments.Add FileNamePDF
    If Send = True Then
        .Send
    Else
        .Display
    End If
End With

Can I use .Hyperlinks.Add?

like image 335
evoandy Avatar asked Mar 05 '13 12:03

evoandy


1 Answers

Presuming your using outlook automation, switch to the HTML mail format:

.BodyFormat = olFormatHTML '// 2
.HTMLBody = strBody 

And use markup for the body:

strBody = "Hello ..<br />next line ..." & _
          "Click <a href=""http://www.foo.com"">here</a> to ..."
like image 189
Alex K. Avatar answered Oct 22 '22 17:10

Alex K.