making hyperlinks relative to current folder

G

Guest

I synchronise my word documents with copies kept on an external drive. Since
hyperlinks use the C drive as the root of the path address, the links don't
work on the synchronised copy. How do I configure the link addresses to be
relative to the folder of the current document, so for example, if the linked
document is in the same folder, then the path address will consist only of
the filename?
TIA ... Greg
 
M

macropod

Hi gvm,

Have you tries setting the hyperlink base? See Word's Help file for the details. Even with the hyperlink base set, I suspect you'll
need to re-set it for each location the files are run from.

Other than that, you can use field coding in Word if the source and target documents can be guaranteed to have the same relative
path between them, but this gets complicated once you start going across directory trees - and doesn't work if the files are on
different drives. Even when it does work, I'm not sure the hyperlink path you get by hovering the mouse of the hyperlink will
display correctly. The field coding is far from obvious, so here's a few pointers:

First off, Insert a FILENAME field, with the path switch (see under Insert|Field), anywhere in your document.

Next, press Alt-F9 to reveal your document's field codes. The FILENAME field will look like:
"{FILENAME \p}
and the hyperlink fields will look something like:
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext"}
or :
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext" \l "BookmarkName"}
The hyperlink fields might have other switches after the file's name, which you'll probably want to keep, but they aren't relevant
to the rest of the discussion below. You can find out what the switches are for from Word's help file, or via
Insert|Field|Hyperlink.

Then, to make an HYPERLINK field look in the current folder, copy & paste the FILENAME field into it, replacing the document path
and inserting '\\..\\' between that and the hyperlink file's name, thus:
{HYPERLINK "{FILENAME \p}\\..\\Filename.Ext"}

How this works: The FILENAME \p field extracts the current file’s name and path. The following '\\..\\' tells Word to ignore the
filename and get just the path. Then all you need to do is to add the source file’s name & extension.

The same approach can be extended to implement a form of relative addressing. For example:
{HYPERLINK "{FILENAME \p}\\..\\My Pictures\\Filename.Ext"}
looks in the child folder named 'My Pictures' and:
{HYPERLINK "{FILENAME \p}\\..\\..\\Filename.Ext"}
looks in the parent folder, while:
{HYPERLINK "{FILENAME \p}\\..\\..\\My Pictures\\Filename.Ext"}
looks in the parent folder, then its child folder named 'My Pictures' (a sibling folder, if you like). Do note that, whilst you can
go down the file tree by adding however many sets of '..\\' you need, you've got to give explicit folder names for navigating back
up it.

The same technique works with INCLUDETEXT, INCLUDEPCTURE & RD fields, but not with LINK fields.

Cheers
 
G

Guest

Thanks Macropod, that helps alot. Now when I insert a link to a file name
that contains a space, Word inserts the characters %20 instead of a space.
Strangely, it doesn't happen on every occasion but it does interfere with
correct operation of the link. Why is that?
TIA ... Greg

macropod said:
Hi gvm,

Have you tries setting the hyperlink base? See Word's Help file for the details. Even with the hyperlink base set, I suspect you'll
need to re-set it for each location the files are run from.

Other than that, you can use field coding in Word if the source and target documents can be guaranteed to have the same relative
path between them, but this gets complicated once you start going across directory trees - and doesn't work if the files are on
different drives. Even when it does work, I'm not sure the hyperlink path you get by hovering the mouse of the hyperlink will
display correctly. The field coding is far from obvious, so here's a few pointers:

First off, Insert a FILENAME field, with the path switch (see under Insert|Field), anywhere in your document.

Next, press Alt-F9 to reveal your document's field codes. The FILENAME field will look like:
"{FILENAME \p}
and the hyperlink fields will look something like:
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext"}
or :
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext" \l "BookmarkName"}
The hyperlink fields might have other switches after the file's name, which you'll probably want to keep, but they aren't relevant
to the rest of the discussion below. You can find out what the switches are for from Word's help file, or via
Insert|Field|Hyperlink.

Then, to make an HYPERLINK field look in the current folder, copy & paste the FILENAME field into it, replacing the document path
and inserting '\\..\\' between that and the hyperlink file's name, thus:
{HYPERLINK "{FILENAME \p}\\..\\Filename.Ext"}

How this works: The FILENAME \p field extracts the current file’s name and path. The following '\\..\\' tells Word to ignore the
filename and get just the path. Then all you need to do is to add the source file’s name & extension.

The same approach can be extended to implement a form of relative addressing. For example:
{HYPERLINK "{FILENAME \p}\\..\\My Pictures\\Filename.Ext"}
looks in the child folder named 'My Pictures' and:
{HYPERLINK "{FILENAME \p}\\..\\..\\Filename.Ext"}
looks in the parent folder, while:
{HYPERLINK "{FILENAME \p}\\..\\..\\My Pictures\\Filename.Ext"}
looks in the parent folder, then its child folder named 'My Pictures' (a sibling folder, if you like). Do note that, whilst you can
go down the file tree by adding however many sets of '..\\' you need, you've got to give explicit folder names for navigating back
up it.

The same technique works with INCLUDETEXT, INCLUDEPCTURE & RD fields, but not with LINK fields.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

gvm said:
I synchronise my word documents with copies kept on an external drive. Since
hyperlinks use the C drive as the root of the path address, the links don't
work on the synchronised copy. How do I configure the link addresses to be
relative to the folder of the current document, so for example, if the linked
document is in the same folder, then the path address will consist only of
the filename?
TIA ... Greg
 
M

macropod

gvm said:
Thanks Macropod, that helps alot. Now when I insert a link to a file name
that contains a space, Word inserts the characters %20 instead of a space.
Strangely, it doesn't happen on every occasion but it does interfere with
correct operation of the link. Why is that?
TIA ... Greg

Hi Greg

I have no idea. Perhaps there's a pattern to the behaviour that might help explain it. The '%20' is, however, a common way of
embedding spaces in hyperlinks. Are you sure they weren't already there?

Cheers
 
G

Guest

Hi macropod,
the %20 may have been there already but if it was then it wasn't visible. Is
the %20 like a field code in that it exists but not normally visible? I have
seen similar behaviour when downloading pdf files, ie the spaces within the
filename are filled with %20. I will try and detect a pattern in the symptoms
.... a pattern is not yet obvious though.
cheers
Greg
 
S

Suzanne S. Barnhill

To clarify, %20 is the HTML code for a space. If this bothers you, you can
create hyperlinks with underlines_between_words instead of spaces, or
eliminate the spaces altogether by CapitalizingTheWords.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Thanks for the clarification Suzanne. I created two links to files that were
both in the same folder. Both had spaces in their names. One hyperlink showed
spaces in the link name. The other showed %20's. Any idea why that occurs? Is
there an option somewhere where you can choose not to show html field codes?
TIA ... Greg
 
S

Suzanne S. Barnhill

If it's just a question of your seeing the HYPERLINK field code instead of
the display text, press Alt+F9. And if you haven't created any display text,
right-click and choose Edit Hyperlink to add display text.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Seeing the %20 in the hyperlink name is untidy and unprofessional. Alt F9
removes the appearance of a link altogether. I want the link to appear (ie to
be underlined and to operate if clicked on) but for spaces to appear instead
of %20. The strange thing is that often links do appear with spaces, and on
relatively few times they appear with %20. I don't ever want them to appear
with %20. Is there a fix?
TIA ... Greg
 
S

Suzanne S. Barnhill

I don't think you understand. There are three parts to a hyperlink field:
the actual hyperlink, the display text, and the ScreenTip. You can edit any
one of them. You can absolutely create display text with spaces even if the
hyperlink has %20 instead. See
http://sbarnhill.mvps.org/WordFAQs/HyperlinkProbs.htm.

By default, the display text is the same as the actual hyperlink, but you
can choose any display text you want. It will be formatted with the
Hyperlink character style.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Macropod, I'm confused. When you advise,
First off, Insert a FILENAME field, with the path switch (see under Insert|Field), anywhere in your document.

....anywhere in WHICH document? the document where you want to place the
hyperlink, or the document that contains the destination of the hyperlink?
Or if both documents are in the same folder, maybe it doesn't matter which
one you use to insert a FILENAME field.

Also the FILENAME field is just being used temporarily, right? It doesn't
need to stay there after you've gotten the desired info out of it...


Next, press Alt-F9 to reveal your document's field codes. The FILENAME field will look like:
"{FILENAME \p}
and the hyperlink fields will look something like:
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext"}
or :
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext" \l "BookmarkName"}
The hyperlink fields might have other switches after the file's name, which you'll probably want to keep, but they aren't relevant
to the rest of the discussion below. You can find out what the switches are for from Word's help file, or via
Insert|Field|Hyperlink.

Then, to make an HYPERLINK field look in the current folder, copy & paste the FILENAME field into it, replacing the document path
and inserting '\\..\\' between that and the hyperlink file's name, thus:
{HYPERLINK "{FILENAME \p}\\..\\Filename.Ext"}

How this works: The FILENAME \p field extracts the current file’s name and path. The following '\\..\\' tells Word to ignore the
filename and get just the path. Then all you need to do is to add the source file’s name & extension.

The same approach can be extended to implement a form of relative addressing. For example:
{HYPERLINK "{FILENAME \p}\\..\\My Pictures\\Filename.Ext"}
looks in the child folder named 'My Pictures' and:
{HYPERLINK "{FILENAME \p}\\..\\..\\Filename.Ext"}
looks in the parent folder, while:
{HYPERLINK "{FILENAME \p}\\..\\..\\My Pictures\\Filename.Ext"}
looks in the parent folder, then its child folder named 'My Pictures' (a sibling folder, if you like). Do note that, whilst you can
go down the file tree by adding however many sets of '..\\' you need, you've got to give explicit folder names for navigating back
up it.

The same technique works with INCLUDETEXT, INCLUDEPCTURE & RD fields, but not with LINK fields.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

gvm said:
I synchronise my word documents with copies kept on an external drive. Since
hyperlinks use the C drive as the root of the path address, the links don't
work on the synchronised copy. How do I configure the link addresses to be
relative to the folder of the current document, so for example, if the linked
document is in the same folder, then the path address will consist only of
the filename?
TIA ... Greg
 
M

macropod

...anywhere in WHICH document?

The document containing the hyperlink field.
Also the FILENAME field is just being used temporarily, right? It doesn't
need to stay there after you've gotten the desired info out of it...

Yes. I mentioned copy & paste rather than cut & paste on the basis that you might have more than one hyperlink field, with different
paths, to modify.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

Bob W said:
Macropod, I'm confused. When you advise,
First off, Insert a FILENAME field, with the path switch (see under Insert|Field), anywhere in your document.

...anywhere in WHICH document? the document where you want to place the
hyperlink, or the document that contains the destination of the hyperlink?
Or if both documents are in the same folder, maybe it doesn't matter which
one you use to insert a FILENAME field.

Also the FILENAME field is just being used temporarily, right? It doesn't
need to stay there after you've gotten the desired info out of it...


Next, press Alt-F9 to reveal your document's field codes. The FILENAME field will look like:
"{FILENAME \p}
and the hyperlink fields will look something like:
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext"}
or :
{HYPERLINK "C:\\DocSystem\\Main \\Filename.Ext" \l "BookmarkName"}
The hyperlink fields might have other switches after the file's name, which you'll probably want to keep, but they aren't
relevant
to the rest of the discussion below. You can find out what the switches are for from Word's help file, or via
Insert|Field|Hyperlink.

Then, to make an HYPERLINK field look in the current folder, copy & paste the FILENAME field into it, replacing the document path
and inserting '\\..\\' between that and the hyperlink file's name, thus:
{HYPERLINK "{FILENAME \p}\\..\\Filename.Ext"}

How this works: The FILENAME \p field extracts the current file’s name and path. The following '\\..\\' tells Word to ignore the
filename and get just the path. Then all you need to do is to add the source file’s name & extension.

The same approach can be extended to implement a form of relative addressing. For example:
{HYPERLINK "{FILENAME \p}\\..\\My Pictures\\Filename.Ext"}
looks in the child folder named 'My Pictures' and:
{HYPERLINK "{FILENAME \p}\\..\\..\\Filename.Ext"}
looks in the parent folder, while:
{HYPERLINK "{FILENAME \p}\\..\\..\\My Pictures\\Filename.Ext"}
looks in the parent folder, then its child folder named 'My Pictures' (a sibling folder, if you like). Do note that, whilst you
can
go down the file tree by adding however many sets of '..\\' you need, you've got to give explicit folder names for navigating
back
up it.

The same technique works with INCLUDETEXT, INCLUDEPCTURE & RD fields, but not with LINK fields.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

gvm said:
I synchronise my word documents with copies kept on an external drive. Since
hyperlinks use the C drive as the root of the path address, the links don't
work on the synchronised copy. How do I configure the link addresses to be
relative to the folder of the current document, so for example, if the linked
document is in the same folder, then the path address will consist only of
the filename?
TIA ... Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top