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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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>"
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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