Insert link into email body using VBA

mikechambers

Active Member
Joined
Apr 27, 2006
Messages
397
I can't find this solutions anywhere. I know how to send emails from Excel using VBA. When I get to the Body section, I want to insert a clickable link to a website, and also a clickable link to send an email (not as important as the website). Can this be done? I have found code to insert links to files, but none for website links.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,789
You'd have to use .HTMLBody rather than .Body. Something like this would insert a link to Google with the words "click here" as the clicky:-
Code:
    .HTMLBody = "< a href=""ht tp://www.google.com/"">click here< /a>< br>"
I've inserted spaces after the < characters and in the middle of http to stop the forum software throwing a wobbly but you need to remove them when you use the code.
 
Last edited:

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,789
For an email links, something like this:-
Code:
.HTMLBody = "Email: < a href='mailto:Mike Chambers < mike(at)chambers.com>?Subject=Request for info&Body=Please send me some info.%0A%0AThank you.>Mike< /a>< br>"
That includes a subject line and a bit of text in the body of the new email. You might find this useful: http://www.ianr.unl.edu/internet/mailto.html.

As before, remove the spaces after the < characters and replace (at) with the @ character.
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,789
Oops - correction:-
Code:
.HTMLBody = "Email: < a href='mailto:Mike Chambers < mike(at)chambers.com>?Subject=Request for info&Body=Please send me some info.%0A%0AThank you.[SIZE=3][COLOR=red][B]'[/B][/COLOR][/SIZE]>Mike< /a>< br>"
 

mikechambers

Active Member
Joined
Apr 27, 2006
Messages
397

ADVERTISEMENT

Hey thanks a lot for the help. Worked great. Really appreciate it!
 

chazz

Board Regular
Joined
Jul 24, 2006
Messages
70
You'd have to use .HTMLBody rather than .Body. Something like this would insert a link to Google with the words "click here" as the clicky:-
Code:
    .HTMLBody = "< a href=""ht tp://www.google.com/"">click here< /a>< br>"
I've inserted spaces after the < characters and in the middle of http to stop the forum software throwing a wobbly but you need to remove them when you use the code.

I can't <i>believe</i> how long and hard I had to look to finally find the key: ".HTMLBody".

You rock.
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,789

ADVERTISEMENT

Yes, you're probably right.

:)
 

Harmeet Singh

New Member
Joined
Mar 24, 2014
Messages
3
Oops - correction:-
Code:
.HTMLBody = "Email: < a href='mailto:Mike Chambers < mike(at)chambers.com>?Subject=Request for info&Body=Please send me some info.%0A%0AThank you.[SIZE=3][COLOR=red][B]'[/B][/COLOR][/SIZE]>Mike< /a>< br>"

Can I add two links in the vba? How can I do so? I have below code. .BodyFormat = olFormatHTML
.HTMLBody = str_MsgBody & vbNewLine & "<html><b><font face=Calibri><font size=5><a href='http://qlikr/QvAJAXZfc/opendoc.htm?document=Risk%20Dashboards/VaR_Sign_Off.qvw&host=QVS@qvapp01'>Flash VaR Sign-Off</a>"
.Importance = olImportanceHigh
.Display I want to add one more URL here. Can I do so?
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,789
You can put as many anchors in your HTML as you want- just build the string HTMLBody with the HTML for the anchors in the required place. Here's an example:-

Code:
.HTMLBody = "You can < a href=""ht tp://www.google.com/"">click here< /a>< br>" _
& "or you can < a href=""ht tp://www.google.com/"">click here instead< /a> - < br>" _

& "whichever you prefer.< br>< br>" _ 
& "Email me: < a href='mailto:Ruddles <<me(at)ruddles.com&g;?Subject=Please send me some info'>clicky</a>< br>"
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,606
Messages
5,765,387
Members
425,281
Latest member
tmoreira001

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
Top