Well, here's a solution (based on an idea originally posted in the microsoft.public.word.mailmerge.fields NG by Peter Jamieson, another MS Word MVP) using INCLUDEPICTURE fields as an example:
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. A FILENAME field will look like:
{FILENAME \p}
and an INCLUDEPICTURE fields will look something like:
{INCLUDEPICTURE "C:\\My Documents\\My Pictures\\Image.png "}
or:
{INCLUDEPICTURE "C:/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|Field.
To make an 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 PicturesImage.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: 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.
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\Joe Blow\Documents' and a series of INCLUDEPICTURE fields coded like '{INCLUDEPICTURE "C:\\Users\\Joe Blow\\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\\Joe Blow\\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: The reason for mucking around with the 'INCLUDEPICTURE "' copying & cutting is to avoid updating other kinds of links.
The above solution works with INCLUDEPICTURE, INCLUDETEXT, RD & HYPERLINK fields, but not with LINK fields. 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 INCLUDEPICTURE, INCLUDETEXT, RD, HYPERLINK & LINK fields. 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.
Attached file(s)
-
AutoFldUpdt.zip (1.74K)
Number of downloads: 222
This post has been edited by macropod: 2009-10-15 20:31
Reason for edit:: Added code to the macro to handle documents protected for forms and for folder offsets


MultiQuote several posts