Add Hyperlink to Excel VBA Email Body

MrMaker

Board Regular
Joined
Jun 7, 2018
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have the below code in Excel that generates emails.

I'd like to add a hyperlink to a website in the middle of the email body but can't work out how?

Does anyone know?

VBA Code:
Sub SendEmails()


Dim Emails, Subject, FName, SName, Attachment, Body As String
Dim i As Long
Dim OutApp As Object
Dim OutMail As Object

For i = 2 To Rows.Count

If Cells(i, 1).Value = "" Then
    Exit Sub
End If


Emails = Cells(i, 1).Value
Subject = Cells(i, 2).Value
FName = Cells(i, 3).Value
SName = Cells(i, 4).Value
Attachment = Cells(i, 5).Value
Emails2 = Cells(i, 8).Value


Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
       
    With Dest
        With OutMail
            .SentOnBehalfOfName = "NAME@WORK.co.uk"
            .To = Emails
            .CC = Emails2
            .BCC = ""
            .Subject = Subject
            .Attachments.Add "C:\UsersMYNAME\Desktop\PIC2.jpg", olByValue, 0
            .Attachments.Add "C:\Users\MYNAME\Desktop\PIC1.jpg", olByValue, 0
            .BodyFormat = olFormatHTML
            .HTMLBody = "<p>Hello " & FName & "," & "</p>" & _
            "<p>TEXT PART 1.</p>" & _
            "<p></p>" & _
            "<p>TEXT PART 2.</p>" & _
            "<BODY><IMG src=""cid:PIC1.jpg"" width=485> </BODY>" & _
            "<p></p>" & _
            "<p> Thanks</p>" & _
            "<p></p>" & _
            "<BODY><IMG src=""cid:PIC2.jpg"" width=85> </BODY>"
            .Attachments.Add Attachment
            .Display
            Application.Wait (Now + TimeValue("0:00:01"))
            Application.SendKeys "%s"
            Application.Wait (Now + TimeValue("0:00:01"))
        End With

    End With
 
    Set OutMail = Nothing
    Set OutApp = Nothing
     
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

Many thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Here's one example from a different project :

VBA Code:
Sub Mail_Outlook_With_Signature_Html_2()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
              "Please visit this website to download the new version.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
              "<br><br><B>Thank you</B>"

    On Error Resume Next

    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = strbody ' & "<br>" & Signature
        '.Send    'or use .Display
        .Display
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Upvote 0
Thanks very much.

Taking the relevant lines of code out I can only get it to embed the link at the top of the email...I need it somewhere in the middle of the email body (say after TEXT PART 1).

Any ideas?
 
Upvote 0
VBA Code:
Sub Mail_Outlook_With_Signature_Html_2()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim SigString As String
    Dim Signature As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
              "<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
              "Please visit this website to download the new version.<br>" & _
              "Let me know if you have problems.<br>" & _
              "<br><br><B>Thank you</B>"


    On Error Resume Next

    With OutMail
        .To = "ron@debruin.nl"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = strbody ' & "<br>" & Signature
        '.Send    'or use .Display
        .Display
    End With

    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top