[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1186
  • Last Modified:

Inserting Hyperlink to Local File in Outlook Email

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

    mydata.PutInClipboard

    GoTo quit

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

quit:
End

End Sub

0
GrayStrickland
Asked:
GrayStrickland
  • 3
  • 2
2 Solutions
 
shantelechyCommented:
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
0
 
GrayStricklandAuthor Commented:
>> 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."

0
 
shantelechyCommented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
shantelechyCommented:
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! ;)
0
 
GrayStricklandAuthor Commented:
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....
0
 
male787827Commented:
Shantelechy's solution should work in all email formats, including plain text, if you put 'file:' before the link:

file:\\bambam\clients\1835\0001\ltr%20Mike%20Harding%2002.doc

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

Good luck!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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