Use vba to insert website hyperlink to email body

Leeinsa

Board Regular
Joined
Jul 24, 2009
Messages
96
Hi guys,

This sounded so simple when I thought about doing it, but I cannot find the answer anywhere.

I have a macro in an excel 2007 workbook, i have a macro which takes data from various worksheets within the workbook and contructs emails (outlook 2007) automatically. Everything works great except:-

at the bottom of my message body, i want to add a hyperlink to our website, but it appears on the email as plain text, not a hyperlink. Outlook is set up to send emails as HTML.

The body of the email is constructed using srting variables so the macro code for the email body loos something like this,

dim strBody as string, strWeb as hyperlink

strWeb = "www.mywebsite.com"
strBody = "blah blah blah" & "<br>" & "Regards," & "<br>" & strWeb


Anybody have any idea, how i should format the hyperlink so it shows up on the email as a usable active hyperlink?

Any help much appreciated.
Lee.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,344
Office Version
  1. 365
Platform
  1. Windows
You need to use the HTMLBody property for the message body and set it to the required HTML code for your link etc.

I can't seem to be able to post an example, the board software seems to be parsing the HTML.
 

Leeinsa

Board Regular
Joined
Jul 24, 2009
Messages
96
Hi Norie,

Thanks for the reply, I tried using HTMLBody attribute as shown below but I get a syntax error. Any idea's why? I have tried encapsulating everything in " marks but still no joy.

'With OutMail
' .To = addtemp
' .CC = cctemp
' .BCC = bcctemp
' .Subject = subtemp
' .HTMLBody = Google

' .Display
'End With

Many thanks,
Lee.
 
Last edited:

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,344
Office Version
  1. 365
Platform
  1. Windows
Lee

As you can see the board has parsed what you posted and is showing the link not the code.

I can only guess that the syntax error is something to do with quotes.

I think you need quotes around the URL when creating a link in HTML.

I know there is a way to post HTML code but I've just forgotten it.:eek:
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,916
Messages
5,834,363
Members
430,279
Latest member
mkasledge1

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