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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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