Thanks Thanks:  0
Likes Likes:  0
Results 1 to 9 of 9

Thread: Insert link into email body using VBA

  1. #1
    Board Regular
    Join Date
    Apr 2006
    Posts
    395
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Insert link into email body using VBA

    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.

  2. #2
    Board Regular Ruddles's Avatar
    Join Date
    Aug 2010
    Location
    Glevum Castra, Britannia
    Posts
    5,770
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    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 by Ruddles; Apr 8th, 2011 at 05:46 PM.
    R.
    ---
    On two occasions I have been asked, 'Pray, Mr Babbage, if you put into the machine wrong figures, will the right answers come out?'
    I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

  3. #3
    Board Regular Ruddles's Avatar
    Join Date
    Aug 2010
    Location
    Glevum Castra, Britannia
    Posts
    5,770
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    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.
    R.
    ---
    On two occasions I have been asked, 'Pray, Mr Babbage, if you put into the machine wrong figures, will the right answers come out?'
    I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

  4. #4
    Board Regular Ruddles's Avatar
    Join Date
    Aug 2010
    Location
    Glevum Castra, Britannia
    Posts
    5,770
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    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.'>Mike< /a>< br>"
    R.
    ---
    On two occasions I have been asked, 'Pray, Mr Babbage, if you put into the machine wrong figures, will the right answers come out?'
    I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

  5. #5
    Board Regular
    Join Date
    Apr 2006
    Posts
    395
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

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

  6. #6
    Board Regular
    Join Date
    Jul 2006
    Posts
    70
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    Quote Originally Posted by Ruddles View Post
    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 believe how long and hard I had to look to finally find the key: ".HTMLBody".

    You rock.

  7. #7
    Board Regular Ruddles's Avatar
    Join Date
    Aug 2010
    Location
    Glevum Castra, Britannia
    Posts
    5,770
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    Yes, you're probably right.

    R.
    ---
    On two occasions I have been asked, 'Pray, Mr Babbage, if you put into the machine wrong figures, will the right answers come out?'
    I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

  8. #8
    New Member
    Join Date
    Mar 2014
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    Quote Originally Posted by Ruddles View Post
    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.'>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 & "Flash VaR Sign-Off"
    .Importance = olImportanceHigh
    .Display I want to add one more URL here. Can I do so?

  9. #9
    Board Regular Ruddles's Avatar
    Join Date
    Aug 2010
    Location
    Glevum Castra, Britannia
    Posts
    5,770
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Insert link into email body using VBA

    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< br>"
    R.
    ---
    On two occasions I have been asked, 'Pray, Mr Babbage, if you put into the machine wrong figures, will the right answers come out?'
    I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •