Inserting Hyperlink to Local File in Outlook Email

Posted on 2005-04-20
Last Modified: 2008-03-17
I have written a macro in Word (see end of this message) which creates a message that I paste into an Outlook email. The message contains the name of  a file that I want my secretary to proofread. I run it when I have the file in question open in Word, then close the document. If the file name (or its path) has no spaces in it, I get a click-able link to the file, but if there are any spaces, the link is broken at the first space.

Q. -- How could I modify the macro so that what I get to paste into the Outlook email will create a clickable link to the file -- even if the file name (or path) contains spaces?

You can manually make a hyperlink in Outlook using the "Tools, Insert Hyperlink" command. And the actual html code that is inserted will be like this:

   <A href="file://Bambam/Clients/Letter to My Client.Doc">file://Bambam/Clients/Letter to My Client.Doc</A>

although once inserted will look like:

   file://Bambam/Clients/Letter to My Client.Doc

However, if you just manually insert the same code into the body of the email, you don't get a functional hyperlink. You just get the raw code.

Sub Proofread()
If ActiveDocument.FullName = "" Then GoTo nameit

Dim currname As String
currname = "Please open " + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10) + ActiveDocument.FullName + Chr$(13) + Chr$(10) + Chr$(13) + Chr$(10) + "and review it, making any corrections you think appropriate, then print for my signature."

Dim mydata As Object
    Set mydata = New DataObject
    mydata.SetText currname


    GoTo quit

MsgBox ("This document has not been named or saved")


End Sub

Question by:GrayStrickland
    LVL 4

    Assisted Solution

    In order for the link to function when you "just insert ... to the body of the email" any space in your document path string must be replaced by %20

    Author Comment

    >> replace any space in your document path string with %20

    That does not work 100%

    1.  If I type \\bambam\clients\1835\0001\ltr%20Mike%20Harding%2002.doc in Word, I get a hyperlink which will open
    \\bambam\clients\1835\0001\ltr Mike Harding 02.doc.

    2.  If I do the same in an HTML formated message in Outlook, it also works.

    3.  If I do the same in a plain-text formated message in Oultook, I get what appears to be a hyperlink (blue underline), notwithstanding that it's a plain text message, but when I click on it, Outlook says, "Outlook cannot find file [name of file] Make sure the path or internet address is correct."

    LVL 4

    Expert Comment

    Since you cannot put extra intructions (html or whatever) into plain text and the ascii character space which can be done using alt(numpad)0160 does not work either

    ... the answer to your question falls back to directory and document naming best practices. __Folder_and_File_names_should_not_have_spaces__ ;) . Replacing the spaces in your path with _ or - is the solid if not the only possible solution.
    LVL 4

    Expert Comment

    Unfortunately Windows doesn't follow the best practices so you may be hooped if your document is in something like C:\Program Files

    But if it's in a networked drive that can be modified to have no spaces you're in luck.

    Someone please correct me if I'm wrong... I hate saying it cannot be done! ;)

    Author Comment

    I think I'll revise my Word macro (1) to pass the path and filename to a variable where the spaces can be replaced with %20 as suggested, then (2) create the Outlook email in HTML format with the link I want. That will work.

    I'll post the code back here on the off chance anyone cares....
    LVL 2

    Accepted Solution

    Shantelechy's solution should work in all email formats, including plain text, if you put 'file:' before the link:


    You can also put < > around a link to force acceptance of a space.  Unfortunately this will not work in HTML emails.

    Good luck!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    My experience with Windows 10 over a one year period and suggestions for smooth operation
    Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now