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.
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,786
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,786
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,786
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,786

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,786
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>"
 

Watch MrExcel Video

Forum statistics

Threads
1,114,521
Messages
5,548,542
Members
410,847
Latest member
shaun32
Top