Avatar of grayco
graycoFlag for United States of America

asked on 

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
    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

End Sub
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Wayne Taylor (webtubbs)
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

do you need any further assistance here?
Comment answered question
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo