Make Word Hyperlinks Portable when Copied to Another Computer

Hi Experts,
How can I change the all of the hyperlinks in a Word 2010 document so that the document and a folder containing a group of target documents can be copied while keeping all links intact on any computer?

DrTribos solved a huge problem last week with his macro that copies hyperlinks from Doc2 to Doc1, based on matching a column of names in both docs. However, when I try to copy Doc1 and the folder of documents that are the targets of the links, it breaks the links. I need to be able to copy Doc1 and the folder of documents to flash drives and CDs, send them to recipients, and have the links still work, after they are copied onto the recipient's computer. I've attached an example of Doc1 and here is an example of a link in Doc1: D:\Users\Tom2QA\Documents\_Homework\HomeTest\DocumentsExport\FSLT-M1.31.docx

I need a solution that makes the links "portable" and a macro that applies the solution to the existing hyperlinks in Doc1.

Your assistance is greatly appreciated!
TomQA17025Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DrTribosCommented:
Hmmm can we assume the relative locations of each document is the same?
DrTribosCommented:
Have a look here: support.microsoft.com/kb/903163 for the background information.
Definitions and examples
•Hyperlink
A hyperlink is colored and underlined text or a colored and underlined graphic that you click to open any one of the following items:¿A file
¿A location in a file
¿A Web page on the Web
¿A Web page on an intranet
¿A Gopher, Telnet, or File Transfer Protocol (FTP) site
Additionally, you can click a hyperlink to view newsgroups.
•Absolute hyperlink
An absolute hyperlink is a hyperlink that contains the full address of the destination file or of the Web site. The following address is an example of a full address in an absolute hyperlink:
http://www.microsoft.com/support 

•Hyperlink base
A hyperlink base is the path that is shared by the file that contains the hyperlink and the destination file.
•Relative hyperlink
 A relative hyperlink is a hyperlink that contains an address that is relative to the address of the destination file. The address of the destination file is also known as the hyperlink base.

For example, a document has the following hyperlink base:
C:\Documents and Settings\Username\My Documents
A document that is named "Sales.doc" is located at the following file path:
C:\Documents and Settings\Username\My Documents\April\Sales.doc
The relative hyperlink to this document contains only the relative address to Sales.doc. Therefore, the relative hyperlink contains the following address:
April\Sales.doc

Method 1: Word 2010
1.Open the document in which you want to use an absolute hyperlink.
2.On the File menu, click Info.
3. Click the Properties dropdown under the document window.
4. Click Advanced Properties.
5. Click the Summary tab.
6. In the Hyperlink Base box, type x, and then click OK .

Method 1: Word 2010
1. Open the document in which you want to use an absolute hyperlink.
2.On the File menu, click Info.
3. Click the Properties dropdown under the document window.
4. Click Advanced Properties.
5.Click the Summary tab.
6.In the Hyperlink Base box, type the path that you want to use for all the hyperlinks that you create in this document.
7. Click OK .
DrTribosCommented:
Hi Tom -

Graham is right, this will encourage other experts to participate which will expose you to more ways of thinking and lead to faster solutions.  At an absolute minimum link to the related question will help :-)
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

DrTribosCommented:
Hyperlink base
TomQA17025Author Commented:
Graham,
Now I know that I can link questions to other questions, in this case, my related question.

DrTribos,
The relative locations of Doc1 and the folder will remain constant, so Doc1 will always be in a folder that also contains the documents folder,  I read the MS KB article first, but I can't successfully apply what it is telling me, meaning that I can't get the links to change or stay permanent. Following your screen shot, I entered an "X" in the Hyperlink Base of Doc1. I see that the links change to only the target document name, but when I select the link, Word reports the "address is not valid..." which seems to make sense because it doesn't know the target doc is in a folder.
In my related question, the hyperlinks were originally created in an html index file in the same folder as the target docs. I opened the html file and saved it as a Word doc, which I named Doc2 and have attached. Your macro copied the links from Doc2 to Doc1. So it seems if I can get the links in Doc2 to become portable, those same links in Doc1 should also be portable?
Doc2-Short-List.docx
DrTribosCommented:
Ok...

Two approaches... I noticed that you are using a HTML file that you converted back to word.  Without going into the reason for you doing this it opens up the possibility of editing that using a simple (although powerful) text editor like NotePad++.

I would simply perform a find and replace within the hyperlink tags to remove the part of the path you don't want.

Failing that - to achieve the desired outcome in Word I had to delete and recreate the hyperlinks.  I am sure a macro could do this but if you were simply using Word as a means to an end then I would give NotePad++ a go.

NotePad++ approach is like this (also NP++ is cool so you should have it):
Your links look like: D:\Users\Tom2\Documents\_Homework\Export Test 06-05 and Later\HomeTest\DocumentsExport06-05packed\FSAS-M1.03.docx

So you can use:
find: "D:\Users\Tom2\Documents\_Homework\Export Test 06-05 and Later\HomeTest\DocumentsExport06-05packed\"

replace: "/"

(I think the slash is reversed, you can check that detail)

HTH
TomQA17025Author Commented:
I don't know anything about HTML so that's why I open and save the HTML file in Word. Also, I knew ultimately the end result had to be a Word doc. I downloaded NotePad++ and opened the HTML file. As I feared, it's all Greek to me. I don't see a hyperlink, and even when I put it into the Find, it doesn't find anything. Each document looks like: <td><a href='FSFP-M2-Appendix B.docx'>FSFP-M2-Appendix B</a></td> but where are the links?
I can see the utility of doing a find and replace, but is the "/" the secret to making the links portable?
Much thanks,
Tom
DrTribosCommented:
Hi Tom - in HTML the <a href ...>Text</a> is the hyperlink.  It looks like your hyper link is already relative in the html doc (unless a base is specified somewhere else).

No the "/" is not the secret, sorry for the red-herring.  The "/" is the difference between how file paths are written using different protocols.  Word uses one or the other depending on the situation.  For example:

"/" used in web browser
"\" used in windows explorer

I think it would be better to tackle this from within the original document.  It might be the case that each link needs to be rebuilt.
TomQA17025Author Commented:
Hi Steve,
Do you mean convert the HTML file to Word, as we have been, and then rebuild the links? If so, is that the point to make them relative?
- Tom
DrTribosCommented:
Hi Tom - I was assuming that the Word documents that you provided (previous question) were created in Word.  I'm starting to think that they were converted from HTML... perhaps we have been talking at cross purposes.  Please outline where the original information comes from.

Cheers,
TomQA17025Author Commented:
Hi Steve,
I'll try to redeem myself and tell an accurate story ;-)
Here is the process:
1) An application creates a folder containing documents and an HTML Index file. The Index file contains the links to each document. The path for each link includes the network share, user, subfolder, etc., so I guess it is an "absolute" link? You can see the path when you hover over the link and look at the bottom of the browser window. I don't see the complete path when I look in the file with Notepad++
2) Ultimately, I need to copy the links to a Word document that I create
3) Since I'm going to work with a Word document, I converted the Index file to a Word file, which we have been calling Doc2.
3) The links in Doc2 are copied by your macro to Doc1. This was discussed in the related question.
4) The links in Doc1 need to be portable, so that folder containing the documents and Doc1 can be moved between computers by flash drives or on CDs.

Thanks,
Tom
DrTribosCommented:
You're redeemed :-D

Ok... turned out to be a quick way to achieve this... I've tested on my PC and it works but am not sure if that is because of some specific settings that I have.  Give it a try and see how it goes.

Sub ConvertHyperlinks()

Dim h As Hyperlink
Dim strPath As String   ' This is for optional path (e.g. to change folder level)

strPath = ""  ' <-- can add a path if desired

For Each h In ActiveDocument.Hyperlinks   ' look through links

    Do While InStr(h.Address, "\")   ' remove "\" and everything to the left of it until there are none left
        h.Address = Right(h.Address, Len(h.Address) - InStr(h.Address, "\"))
    Loop
    
    h.Address = strPath & h.Address  ' add optional path, leave blank to add nothing
Next h
End Sub

Open in new window

TomQA17025Author Commented:
Steve,
At James Taylor concert will test asap
Thanks!
DrTribosCommented:
I hope you enjoy both the concert and solution :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TomQA17025Author Commented:
Hi Steve,

Your solution worked!! It's amazing!! I put the folder name and a "\" in the strPath variable, i.e. "TomDoc\" and ran the macro on the Word Index, Doc2. Then ran your previous macro to transfer the links to Doc1. And then, I burned a CD, walked to another computer, opened Doc1 on the CD, and the links worked!!!

We discussed Word setup and there are plenty of comments on the Internet on how Word should be setup for portable (relative) links. In my Word 2010:
1) The Options | Advanced | Web Options | Files | Update links on save: is checked.
2) For both Doc1 and Doc2, I left the individual Document Properties | Summary | Hyperlink base: is blank

Thank you so much for your patience and time on my problem!!

Tom

P.S. The James Taylor concert was excellent!
DrTribosCommented:
Hi Tom - no worries, glad to help :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.