How do I add a Hyperlink to the email body using VBA?

hollifd

Board Regular
Joined
Apr 3, 2002
Messages
248
I want to use VBA code similar to the code below to insert a hyperlink to a file on the server so that recipients of the email can access the file. Is it possible to insert a Hyperlink into the body of the email using code similar to the code below? If so, can you show me how it is done?

Thanks,

David

Code:
Public Sub TestIT()

Set ol = CreateObject("Outlook.application")
Set NewMessage = ol.CreateItem(olMailItem)

With NewMessage
    .Recipients.Add "XXX@XXXXXXX.com"
    .Subject = "This is only a test!"
    .Body = "Please click on the link below..." & vbCrLf & vbCrLf
    
    'How do I add a hyperlink to the email body here????
    
    .Display
End With

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
not tested, but can't you simply add the address to the Body... enclose in <> to be sure that Outlook recognizes it.

Code:
.Body = "Please click on the link below..." & vbCrLf & vbCrLf & "<http:\\www.google.com>"
 

hollifd

Board Regular
Joined
Apr 3, 2002
Messages
248
Nevermind...

I figured it out. Here is how I did it for anyone else that may not know:

Code:
Public Sub TestIT()

Set ol = CreateObject("Outlook.application")
Set NewMessage = ol.CreateItem(olMailItem)

With NewMessage
    .Recipients.Add "XXX@XXXXXXX.com"
    .Subject = "This is only a test!"
    
    'Insert body and Hyperlink below...
    .Body = "Please click on the link below..." & vbCrLf & vbCrLf & _
    "file:\\dbd03\nccode\Router_Proc\04Routing.txt"
    
    .Display
End With

End Sub
 

Forum statistics

Threads
1,136,712
Messages
5,677,335
Members
419,688
Latest member
sarahmichelle

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