Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 04-08-2018, 05:06 PM
macropod's Avatar
macropod macropod is offline Word Fields and Relative Paths to External Files Windows 7 64bit Word Fields and Relative Paths to External Files Office 2010 32bit
Administrator
Word Fields and Relative Paths to External Files
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default Word Fields and Relative Paths to External Files

Word tends to store paths to external files with absolute paths. The fields affected by this include Word's DATABASE, INCLUDEPICTURE, INCLUDETEXT, LINK, RD and HYPERLINK fields. This means that, should you need to move the files as a group to another folder (eg putting them on a CD or USB stick for portability), all the links will break. What is needed is a means of coercing Word into applying some sort of relative path addressing for fields pointing to other files. Even if you omit the path from the field code, in most Word versions it still gets stored in the file's metadata. The only version I know of that doesn't always do this is Word 2010 - and even that seems to vary according to whether the path has ever been stored...

Well, there is a solution (based on an idea originally developed by Peter Jamieson, another MS Word MVP) that works with DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD and HYPERLINK fields, but not with LINK fields. For LINK fields, scroll to the bottom of this thread. The following example employs an INCLUDEPICTURE field, but works equally well with DATABASE, INCLUDETEXT, RD and HYPERLINK fields.

First off, insert a FILENAME field, with the path switch You can create this by pressing Ctrl-F9 (Cmd-F9 on a Mac) to create a pair of field braces anywhere in your document, then typing 'FILENAME \p' between them so that you end up with {FILENAME \p}. Alternatively, for:
• PCs see under Insert|Quick Parts|Field>Filename;
• Macs, Insert|Field|Document Information>Filename.

Next, press Alt-F9 to reveal your document's field codes. The FILENAME field will look like:
{FILENAME \p}
Similarly, your INCLUDEPICTURE field will look something like:
{INCLUDEPICTURE "C:\\Users\\UserName\\My Documents\\My Pictures\\Image.png "}
or:
{INCLUDEPICTURE "C:/Users/UserName/My Documents/My Pictures/Image.png "}
Some fields might have other switches after the file's name, which you might 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|Quick Parts|Field(PC)/Insert|Field(Mac).

Note 1: Word refuses to display INCLUDEPICTURE field codes in the docx/m formats once the document has been saved - you need to save the document in the older doc format before you can access any INCLUDEPICTURE fields. Go figure.

To make the INCLUDEPICTURE field look in the current folder, cut & paste the FILENAME field into it, replacing the document path and inserting '\\..\\' or '/ /' between that and the hyperlink file's name, thus:
{INCLUDEPICTURE "{FILENAME \p}/../Image.png"}
or
{INCLUDEPICTURE "{FILENAME \p}\\..\\Image.png"}

How this works: The FILENAME p field extracts the current file's name and path. The following '\\..\\' or '/../' 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:
{INCLUDEPICTURE "{FILENAME \p}\\..\\My Pictures\\Image.png"}
looks in the child folder named 'My Pictures' and:
{INCLUDEPICTURE "{FILENAME \p}\\..\\..\\Image.png"}
looks in the parent folder, while:
{INCLUDEPICTURE "{FILENAME \p}\\..\\..\\My Pictures\\Image.png"}


looks in the parent folder, then its child folder named 'My Pictures' (a sibling folder, so to speak).

Note 2: You can go down the file tree by adding however many sets of '\\..\\' you need, but you must give explicit folder names for navigating back up it.

If you've got a lot of links to convert, you can use Find/Replace to do the grunt work. For example suppose you've got a document in the folder 'C:\Users\UserName\Documents' and a series of INCLUDEPICTURE fields coded like '{INCLUDEPICTURE "C:\\Users\\UserName\\Documents\\Images\\MyPic .jpg "}'. In this case, the images are in a child folder hanging off the 'Documents' folder. The process you'd use is:
1. Press Alt-F9 to reveal the field codes.
2. Copy 'INCLUDEPICTURE "C:\\Users\\UserName\\Documents' and paste it into the 'Find' box. Do a 'Find' to lock it in.
3. Create a FILENAME field, with the path switch (see above) and insert 'INCLUDEPICTURE "' into the document immediately before it.
4. Cut the 'INCLUDEPICTURE "' and FILENAME field from the document. This puts them in the Windows Clipboard.
5. Insert '^c' in the 'Replace box.
6. Click on 'Replace All'.
7. Copy '\\Images' and paste it into the 'Find' box.
8. Type '\\..^&' into the 'Replace' box.
9. Click on 'Replace All'.
10. Press Ctrl-A then F9 to update the fields.
11. Press Alt-F9 to hide the field codes.

Note 3: The reason for the 'INCLUDEPICTURE "' copying & cutting is to avoid updating other kinds of links. You can omit that part if you're working with multiple kinds of links, except for LINK fields.

The above solution works with DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD and HYPERLINK fields, but not with LINK fields - for which, see below. It doesn't work with LINK fields because they have the nasty habit of converting any embedded fields to plain text immediately they're updated.

Also attached is a macro I've created for automatically updating the field paths for DATABASE, INCLUDEPICTURE, INCLUDETEXT, RD, and HYPERLINK as well as with LINK fields and for other linked objects. To use it, simply extract the file from the zip archive, open up the Word VBE (Alt-F11) and import the file into the document you want to use it with, then save the document.

Enjoy
Attached Files
File Type: zip AutoFldUpdt.zip (1.8 KB, 860 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling data from other files whose paths change sbinder Excel 1 10-01-2017 12:12 AM
Word Fields and Relative Paths to External Files Save external link files with OneNote? salmonrose OneNote 1 10-30-2014 02:59 PM
Has the problem with relative paths been resolved in Word 2010? Aston Word 1 10-24-2012 11:38 PM
Tasks and external files scampsd Outlook 0 11-29-2011 09:36 AM
Word Fields and Relative Paths to External Files Access pst files on external hard drive LOUDONCLEAR Outlook 1 09-22-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft