Cross-Reference Among Documents





Cross-Reference Among Documents

figs/moderate.gif figs/hack78.gif

This hack shows you how to create cross-references among different Word documents.

When you create a cross-reference in Word, no option exists for referencing content in another document. But sometimes you need to split your work into multiple files, like the chapters in a book. (Word once actually encouraged this practice; the Word 2.0 manual says, "If your document is longer than 20 pages, consider creating several smaller documents.") If you use fields and bookmarks, you can create your own dynamic cross-references among separate Word documents.

A cross-reference has two parts: the reference and the target. A target is sort of like an Internet URL, and a reference is like a link to that URL. Each target can have multiple references pointing to it, but each reference can point to only one target. Just like URLs, each target must have a unique identifier.

1 Understanding Word's Native Cross-Referencing

When you make a cross-reference in Word (InsertReferencesCross-reference or InsertCross-reference, depending on your version of Word), it displays the dialog shown in Figure. You can choose between several different reference types, but notice that there's no option for text in another document.

Word's Cross-reference dialog
figs/wrdh_0817.gif


When you create a cross-reference this way, Word inserts a bookmark around the target text. Word hides the bookmark it creates to mark your reference target, but you can see its name if you look in the InsertBookmark dialog and check the "Hidden bookmarks" box, as shown in Figure. If your hidden bookmarks don't show up in the dialog, uncheck and then recheck the box.

You can view your cross-reference bookmarks in the Bookmark dialog
figs/wrdh_0818.gif


Word assigns the bookmark's name, something like "_Ref46516798," to make the bookmark unique. The leading underscore denotes a hidden bookmark.

While the bookmark's name may be unique, it's not very useful. If you need to determine which bookmark belongs to which reference target, the list shown in Figure offers little comfort.

Word's decidedly unhelpful bookmark-naming convention for cross-references
figs/wrdh_0819.gif


Identifying specific bookmarks is an important part of troubleshooting cross-references, because bookmarks behave very, very strangely when you edit the text they enclose. For example, if you add text to the end of a heading that you cross-referenced and update the reference, the new text isn't included in the reference. Figure shows this phenomenon using a manually created bookmark (so the ends are visible), but the same thing happens with Word's cross-reference bookmarks.

When you add text at the end of a bookmarked paragraph, the bookmark doesn't expand
figs/wrdh_0820.gif


The solution? If you need to add text to a reference paragraph, you must put the new text before the last character and then delete the last character. But wait, it gets worse. Inserting text at the beginning of the paragraph works just fine, but if you hit Enter with your cursor at the beginning of the paragraph, the bookmark's beginning gets left behind, as shown in Figure.

A wayward bookmark
figs/wrdh_0821.gif


Now that you've gotten a peek into the way Word cross-references work, you're ready to create your own cross-references between two different documents.

2 Create Cross-References with INCLUDETEXT Fields

To reference text in a different document, you can use the same general method Word does: mark the target with a unique bookmark and then reference the contents of the bookmark with a field.

When you use this technique, put all the related documents in the same folder so they can be moved around together without breaking any references.


For example, say you have a book with six chapters named "Chapter One," "Chapter Two," and so on. Chapter Two contains a section you want to reference in Chapter Three.

First, open the document containing the target (Chapter Two in this example) and go to the heading you want to reference. Select the entire heading, except for the trailing paragraph mark. Select InsertBookmark and give the bookmark a descriptive name, as shown in Figure. Word will warn you if you try to use any illegal characters, such as a space, in the name.

Choose a descriptive and unique name for your bookmark
figs/wrdh_0822.gif


Click the Add button to insert the bookmark. If you've chosen to show bookmarks (select ToolsOptions and click the View tab), the bookmark's ends will appear as grey or black brackets, depending on your version of Word. Don't worry; the bookmarks will not appear when you print the document.

To avoid accidentally deleting or moving one end of a bookmark, you should work with bookmarks visible. You can always use Print Preview to see how your text will look without them.


Next, go to the document and find the location where you want the reference to appear. Press Ctrl-F9 (or select InsertField) to insert a blank set of field braces and type the following between them:

INCLUDETEXT "Chapter Two.doc" 

BookmarkName

Note that you enclose the filename in quotes, but not the bookmark name.

Select the field and press F9. The reference will now display the bookmarked text. With "Field shading" set to Always (select ToolsOptions and click the View tab), you can easily spot your cross-references, as shown in Figure.

A cross-reference to an external Word document
figs/wrdh_0823.gif


If Word displays a "Source File Not Found" error in your INCLUDETEXT field, go to File Open, navigate to the folder containing the source document, and press Cancel. Then select the field and press F9.


With an INCLUDETEXT field, you insert more than just the bookmark's contents. The bookmark itself now appears in the reference document's list of bookmarks.

Any fields in the target text, such as a caption's SEQ field, also get mingled with the reference document's fields, which can throw off caption numbering.


For more hacks about cross-referencing in Word, check out [Post #43] and [Post #44] .


     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows