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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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:
Upvote 0
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.
 
Upvote 0
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>"
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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>"
 
Upvote 0

Forum statistics

Threads
1,213,559
Messages
6,114,302
Members
448,564
Latest member
ED38

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