
Microsoft Word has been around for 26 years now, and it still lacks some common-sense features. For instance, you can’t use a relative path to point to linked documents. This means, if you put together a master document and use “Insert->Object->Text from file” to add a link to other documents, Word will insert the complete path to this linked document. If you move the master and linked documents to another folder, you will get a bunch of these: “Error! Not a valid filename”.
If you expand the field codes to see what is going on (select the item and hit Shift-F9), you’ll see that the link is pointing to the old path. If you edit the field code text and remove the path, but leave the file name, Word will prepend the path that is defined in “Word Options->Advanced->General->File Locations->Documents” (Oh, and if you’re wondering how to get to the “Word Options” menu, look under the oh-so-obvious Office Symbol at the upper left of the Word window).
So, here’s a work-around to enable relative paths to linked documents. You can create a custom document property that contains the path name to the active document’s path and include it in the file name of the INCLUDETEXT field code. This technique is mentioned here.
Linked files use the INCLUDETEXT field code to link to documents like this: {INCLUDETEXT “filename”}. If your linked file is RTF, it looks like this {INCLUDETEXT “filename” \c MSRTF}. You can embed a field code inside a field code to use a custom document property that contains a path like this: {INCLUDETEXT “{DOCPROPERTY pathString}\\fileName”}, where pathString defines the location of the document folder where the files exist, and fileName is the name of the file to link.
Now, you need to automatically set the custom document property pathString to the path of the active document. To do this, you can use a VBA script. You first need a method to write to a custom document property. Here is one that works well. Place that code into “ThisDocument” in you document's VBA editor tree (go to Developer->Visual Basic) to open the VBA editor. If you don’t see the Developer tab, go to the Office Icon->Word Options->Popular and check “Show Developer tab in the Ribbon”.
Now, place this code into the VBA script:
Private Sub Document_Open()
Call WriteProp(sPropName:="pathString",_
sValue:=ActiveDocument.Path,_
lType:=msoPropertyTypeString)End Sub
Every time the document opens, it will assign the active document’s path to the “pathString” document property.
Maybe Microsoft knew about this super simple method and figured there was no need for relative paths;-)