• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 58
  • Last Modified:

Include a hyperlink in the body of an email

Greetings Experts,
I have a maintenance file that includes a "save" button that saves the file and sends two people emails telling them that the file has had an addition.  I have the network address included in the body of the email, but I would like to just click on the address and be able to access the file from the email.  Here is the macro I currently have;


Sub Mail_small_Text_Outlook()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
   
   
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = "A new maintenance item has been added to the Maintenance Log. You can view this file at Y:\Common\Facilities Maintenance\Fac Maint Log.xlsm "
*** this is the line that I would like to fix so the file location is a link***



    On Error Resume Next
    With OutMail
        .To = "Rob Cummings <rcummings@grwater.com>; Glen Ray <gray@grwater.com>"
        .CC = ""
        .BCC = ""
        .Subject = "A maintenance item has been added to the Maint Log"
        .Body = strbody
       
        .Send
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    End With
   
    Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False
    Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False

    ActiveWorkbook.Save
       
   
End Sub
0
grayco
Asked:
grayco
  • 2
  • 2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Use HTMLBody instead of Body and specify your link with HTML...

Sub Mail_small_Text_Outlook()
     Dim OutApp As Object
     Dim OutMail As Object
     Dim strbody As String
     
     
     Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)

     strbody = "A new maintenance item has been added to the Maintenance Log. You can view this file at <a href='Y:\Common\Facilities Maintenance\Fac Maint Log.xlsm'>Y:\Common\Facilities Maintenance\Fac Maint Log.xlsm</a> "

     On Error Resume Next
     With OutMail
         .To = "Rob Cummings <rcummings@grwater.com>; Glen Ray <gray@grwater.com>"
         .CC = ""
         .BCC = ""
         .Subject = "A maintenance item has been added to the Maint Log"
         .HTMLBody = strbody
         .Send
     On Error GoTo 0

     Set OutMail = Nothing
     Set OutApp = Nothing
     End With
     
     Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save As...").Enabled = False
     Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls("Save").Enabled = False

     ActiveWorkbook.Save
     
 End Sub

Open in new window

0
 
Ryan ChongCommented:
a side note...

I think you may consider to remove the line of code: On Error Resume Next and to have a better error handling in your Sub.

if you put the On Error Resume Next in it, the script will keep running, and you will not be notified if that's any errors in sending out the emails.
0
 
Ryan ChongCommented:
do you need any further assistance here?
0
 
Wayne Taylor (webtubbs)Commented:
Comment answered question
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now