We help IT Professionals succeed at work.
Get Started

Sending an email from Excel VBA with a hyperlink that doesn't show the link code

86 Views
Last Modified: 2020-02-18
I have an Excel VBA module that sends an email that includes a hyperlink to a network drive location (that may have spaces). I have some code that sort of works but needs a bit of help...

  Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    strbody = managername & "," & vbNewLine & vbNewLine & _
              "Data has been dumped from the survey controller on project number " & newjob & ".  The name of the file is: " & vbNewLine & vbNewLine & _
              filefromname & vbNewLine & vbNewLine & _
              "and it is located in the following folder:" & vbNewLine & vbNewLine & _
            "<a href=""<file:///" & GetFolder & ">"">" & GetFolder & "</a>" & vbNewLine & vbNewLine & _
                "Comments:" & vbNewLine & surveynotes
    MsgBox strbody
    
    On Error Resume Next
    With OutMail
        .To = manageremail
        .Subject = "Some survey points have been downloaded on one of your projects"
        .Body = strbody
        'You can add a file like this
        '.Attachments.Add ("C:\test.txt")
        .Send   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

Open in new window


The email sends no problem, and the extra chevrons in the string help me pick folders that have spaces in them.  But when the user gets the email, they see the hyperlink source code in the Outlook email like this: (PS - the link works no problem)

HTML is showing
instead of seeing it neatly like this:

What I want it to look like
If I grab the "strbody" variable and paste it into dreamweaver or some other editor, it looks fine, but when the Outlook email is received, the HTML code for the link shows up.  What can I do so that the user doesn't see all the <a href> text that goes with the hyperlink?


Thanks very much!
Comment
Watch Question
Social distance - Wear a mask - Don't touch your face - Wash your hands for 20 seconds
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE