Adding a hyperlink into the body of an email

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
161
Hi all,

I'm having some issues trying to insert a hyperlink into the body of an email that is generated using VBA from Excel. All of my code works except from the part where I insert the link. After <A HREF = if I type a link manually there instead of trying to insert from a textbox then it works but using the below code the link inserted is me.txtinvoicelink.value instead of the link in that textbox. I hope this makes sense.

Any help is appreciated as always.

Dan

VBA Code:
Private Sub CommandButton1_Click()
    
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim xx As String
    
    xx = "Pack 1"

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

    strbody = "<font size=3>Hi " + ActiveCell.Offset(, -9).Value + ",<br><br>" & _
              "Please find the link " + "<A HREF=me.txtinvoicelink.value>here</A>" + " to your invoice." & _
              "<p>As soon as payment is received your order will be shipped within 48 hours and a tracking link provided.</font>"

    On Error Resume Next

    With OutMail
        .SentOnBehalfOfName = "XX"
        .display
        .To = ActiveCell.Offset(, -3).Value
        .CC = ""
        .BCC = ""
        .Subject = "XX"
        .HTMLBody = strbody & .HTMLBody
        .display
    End With

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

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Maybe
VBA Code:
    strbody = "<font size=3>Hi " + ActiveCell.Offset(, -9).Value + ",<br><br>" & _
              "Please find the link <A HREF=" & Me.txtinvoicelink.Value & ">here</A>  to your invoice." & _
              "<p>As soon as payment is received your order will be shipped within 48 hours and a tracking link provided.</font>"

Bye
 
Upvote 0
Solution

Forum statistics

Threads
1,214,877
Messages
6,122,051
Members
449,064
Latest member
scottdog129

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