Hyperlink with friendly name

Gerrit.B

Board Regular
Joined
Aug 10, 2004
Messages
237
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I create in MS Excel an email with the tracking number of their shipment.
To create the hyperlink in VBA I use
VBA Code:
URL = "http://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&loc=en_nl&tracknum=" & ActiveSheet.Cells(11, 1).Value
How can I create a hyperlink that only shows "ActiveSheet.Cells(11, 1).Value" instead of this long url.

Regards,

Gerrit
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You can normally use the TextToDisplay parameter as shown below:

VBA Code:
ActiveSheet.Hyperlinks.Add anchor:=ActiveSheet.Cells(11, 2), Address:=URL, TextToDisplay:=CStr(ActiveSheet.Cells(11, 1).Value)

However, since you didn't tell us how you are using the Hyperlinks.Add method, I am not sure if this is the way you are using or creating a formula by using the HYPERLINK function in VBA, or something totally different.
 
Upvote 0
Thanks Suat,

I use vba code below, and do not know were to place TextToDisplay.

VBA Code:
Sub SendingSheetAttUPS()

Dim oMSOutlook As Object
Dim oEmail As Object
Dim sAttachment As String
Dim URL As String


Set oMSOutlook = CreateObject("Outlook.Application")
Set oEmail = oMSOutlook.CreateItem(olMailItem)

sAttachment = "H:\Full Order Documents\"

URL = "http://wwwapps.ups.com/WebTracking/processRequest?HTMLVersion=5.0&Requester=NES&AgreeToTermsAndConditions=yes&loc=en_nl&tracknum=" & ActiveSheet.Cells(11, 1).Value


With oEmail
.To = ActiveSheet.Cells(2, 2).Value
.CC = ActiveSheet.Cells(3, 2).Value
.BCC = ActiveSheet.Cells(4, 2).Value
.Subject = ActiveSheet.Cells(6, 1).Value & " " & ActiveSheet.Cells(9, 1).Value
.Body = ActiveSheet.Cells(7, 1).Value & Chr(13) & Chr(13) & URL

' You can add other files by uncommenting the following line.
If ActiveSheet.Cells(9, 3).Value = "PDF" Then
.Attachments.Add sAttachment & ActiveSheet.Cells(9, 1).Value & ".pdf"
Else
.Attachments.Add sAttachment & ActiveSheet.Cells(9, 1).Value & ".zip"
End If


.Display
End With


Set oMSOutlook = Nothing
Set oEmail = Nothing

End Sub
 
Upvote 0
I see. You want a clickable link in the email message with the tracking number as the displayed text. Please ignore my previous post, because it has nothing to do with the Hyperlinks in Excel.

In order to make it work as explained, you need to use .HTMLBody property instead of .Body.
Please disable the line starting with .Body in your code and use the one I wrote below and try it. Please note since we are using HTMLBody now, we need "<br>" instead of Chr(13) to create new lines.

VBA Code:
'.Body = ActiveSheet.Cells(7, 1).Value & Chr(13) & Chr(13) & URL
.HTMLBody = ActiveSheet.Cells(7, 1).Value & "<br><br>" & "<a href=""" & URL & """>" & ActiveSheet.Cells(11, 1).Value & "</a>"
 
Upvote 0
Glad to hear it helps. Thanks for the feedback.

Please consider marking the post as solution that answered your question to help future readers. It is an easy click on the tick mark icon right next to that post but might be a huge help for someone else looking for a similar solution.

1660294608151.png
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

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