hyperlink with email (1 Viewer)

kitty77

Registered User.
Local time
Today, 02:00
Joined
May 27, 2019
Messages
331
I'm using the following code to send an email. Works great. How can I make [Mtrack] be a clickable link in the email? And when you click the link
it would follow: Application.FollowHyperlink "http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=" & [Mtrack]

Thanks!

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.To = [email1]
'.CC = [email2]
'.BCC = ""
'.Attachments.Add
.Subject = "Shipping Confirmation!"
.Body = "A package is coming your way." & Chr(10) & Chr(10) & _
"Tracking No: " & [Mtrack] & Chr(10) & _
"Date Sent: " & [Mdatesent] & Chr(10) & Chr(10) & _
'.Send
.Display
End With
 

plog

Banishment Pending
Local time
Today, 01:00
Joined
May 11, 2011
Messages
10,345
An email is HTML, so you need to have your code produce an HTML link in the body of the message. The basic coding of an HTML link is as such:

<a href="URL">DISPLAYTEXT</a>

Replace URL with the link to go to when clicked.
Replace DISPLAYTEXT with what you want the link to say.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:00
Joined
Oct 29, 2018
Messages
14,544
To use HTML in an email, you'll also have to use:

.HTMLBody

instead of:

.Body
 

plog

Banishment Pending
Local time
Today, 01:00
Joined
May 11, 2011
Messages
10,345
Yes that looks good. Be sure to escape your double quotes when building your string in VBA. Or switch to single quotes.
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:00
Joined
Mar 14, 2017
Messages
4,314
what I like to do in these situations is create a perfectly formatted email draft precisely the way I want it to look in the email. After that I right click in the email and choose view source. in the resulting text file I edit the variables with the name something like placeholder_variable. Then I store that text in a database table column. then at run time as DB guy mentioned I use HTML body and then I use the replace function to replace placeholders in the HTML text with the real thing .. after that you have a perfectly formatted email with as fancy HTML as you might want, done totally the easy way .. without knowing any HTML
 

plog

Banishment Pending
Local time
Today, 01:00
Joined
May 11, 2011
Messages
10,345
Change the double quotes around the URL to single quotes.
 

arnelgp

error reading drive A:
Local time
Today, 14:00
Joined
May 7, 2009
Messages
11,995
Code:
Dim TrackingNo As String
TrackingNo = "<a href=""http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=" & [MTrack] & """>" & [MTrack] & "</a>"

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.To = [email1]
'.CC = [email2]
'.BCC = ""
'.Attachments.Add
.Subject = "Shipping Confirmation!"
.HTMLBody = "A package is coming your way.<br>" & _
"Tracking No: " & TrackingNo & "<br>" & _
"Date Sent: " & [Mdatesent]
'.Send
.Display
End With
 

Isaac

Lifelong Learner
Local time
Yesterday, 23:00
Joined
Mar 14, 2017
Messages
4,314
Just sayin, my way is a lot easier than learning html :)
 

kitty77

Registered User.
Local time
Today, 02:00
Joined
May 27, 2019
Messages
331
Code:
Dim TrackingNo As String
TrackingNo = "<a href=""http://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=" & [MTrack] & """>" & [MTrack] & "</a>"

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.To = [email1]
'.CC = [email2]
'.BCC = ""
'.Attachments.Add
.Subject = "Shipping Confirmation!"
.HTMLBody = "A package is coming your way.<br>" & _
"Tracking No: " & TrackingNo & "<br>" & _
"Date Sent: " & [Mdatesent]
'.Send
.Display
End With
How can I add a space or two since I switched to .htmlbody? What is the format for adding spaces?

Thanks!
 

plog

Banishment Pending
Local time
Today, 01:00
Joined
May 11, 2011
Messages
10,345
To add a space you just type a space in your string. To add more than 1 space consecutively requires you use an HTML code:

&nbsp; &nbsp;

Paste that into your string and the HTML will have 3 spaces (the 2 codes + the actual space between them)
 

kitty77

Registered User.
Local time
Today, 02:00
Joined
May 27, 2019
Messages
331
To add a space you just type a space in your string. To add more than 1 space consecutively requires you use an HTML code:

&nbsp; &nbsp;

Paste that into your string and the HTML will have 3 spaces (the 2 codes + the actual space between them)
So how should it look using my code below? Adding two spaces between "Tracking No" and Tracking No.

"Tracking No:" & TrackingNo & "<br>" & _
 

plog

Banishment Pending
Local time
Today, 01:00
Joined
May 11, 2011
Messages
10,345
"Tracking No: &nbsp;" & TrackingNo & "<br>" & _
 

Users who are viewing this thread

Top Bottom