News, tips, advice, support for Windows, Office, PCs & more
Home icon Home icon Home icon Email icon RSS icon

We're community supported and proud of it!

  • Word Fields and Relative Paths to External Files

    Home Forums AskWoody support Productivity software by function MS Word and word processing help Word Fields and Relative Paths to External Files

    • This topic has 1 voice and 0 replies.
    Viewing 0 reply threads
    • Author
      • #489359

        Word tends to store paths to external files with absolute paths. The fields affected by this include Word’s 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, here’s a solution (based on an idea originally developed by Peter Jamieson, another MS Word MVP). The solution uses an INCLUDEPICTURE field as an example:

        First off, insert a FILENAME field, with the path switch (see under Insert|Field [Word 2003 7 earlier] or Insert|Quick Parts|Field [Word 2007 & later]), anywhere in your document.
        Next, press Alt-F9 to reveal your document’s field codes. A 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 “}
        {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|Field.

        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”}
        {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: 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:UsersUserNameDocuments’ 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: 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 INCLUDEPICTURE, INCLUDETEXT, RD and 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 and 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.


        Note: Any discussions should be made in a new thread – they cannot be added to this one.

        Paul Edstein
        [Fmr MS MVP - Word]

    Viewing 0 reply threads

    Please follow the -Lounge Rules- no personal attacks, no swearing, no politics or religion.

    Reply To: Word Fields and Relative Paths to External Files

    You can use BBCodes to format your content.
    Your account can't use Advanced BBCodes, they will be stripped before saving.