April 2006 Newsletter
News from Home and Abroad
Word's Best Kept Secret; the RD Field Code
by Cathy Clarke STC UK, Senior Member
Word documents can get big, especially when they are full of images. Eventually, the only sensible thing to do is to split them into multiple documents. "But what about the Table of Contents", someone mutters. "I don't want to build a TOC by hand!" But is it really such a problem? Well, not if you know about Word's best kept secret, the RD field code.
Word's field codes have been around since 1992, but few people know about them and even less people use them. A quick search on Google showed there is little information on the web about field codes in general and almost nothing about the RD code.
The RD field code lets you build a Table of Contents across multiple documents. The following is an example:
Please note: This is NOT a discussion about Master documents. Referenced documents are quite different!! Files are totally independent of each other, and when building a TOC, Word opens one document at a time, stores the headings in each and finally creates the TOC. You can use the same method to build an index or table of figures.
We'll call them ReferencedDoc1.doc and ReferencedDoc2.doc and TOCdoc.doc. All documents reside in the same folder.
Each document uses styles to assign Heading 1, Heading 2, Heading 3 and Body Text. The page numbering in the second document has been restarted to follow on from the first document. In our example the second document starts at page 22.
To retrieve the headings from the other chapters, you need to add RD field codes that point to the other files. Do this as follows:
Please note: This is NOT a discussion about Master documents. Referenced documents are quite different!! Files are totally independent of each other, and when building a TOC, Word opens one document at a time, stores the headings in each and finally creates the TOC. You can use the same method to build an index or table of figures.
Simple Example
The Documents
Let's start with a very simple example; 2 chapters and a separate document containing the TOC.
We'll call them ReferencedDoc1.doc and ReferencedDoc2.doc and TOCdoc.doc. All documents reside in the same folder.
Each document uses styles to assign Heading 1, Heading 2, Heading 3 and Body Text. The page numbering in the second document has been restarted to follow on from the first document. In our example the second document starts at page 22.
Setting up the Table of Contents
Set up the Table of Contents in TOCdoc.doc. Make sure that all the documents are in the same folder. Now, insert a Table of Contents as follows:- Choose Reference from the Insert menu.
- Choose Index and Tables from the Reference menu
- Click OK.
- Press Ctrl + F9 to open a pair of Field Code Braces
.
- Now, add the RD field code details for the first document. These are as follows:
- Repeat the process for the second document.
- Finally, select all the text on the page and then press F9 to update fields. The error message disappears and is replaced by the headings from the other documents.
Getting a More Sophisticated TOC Layout
The example above has a very simple layout. The TOC field code has switches that let you create more sophisticated layouts. By using some of Word's other field codes and switches you can:- Include a chapter prefix before a page number, for example, 2-19. (Use the seqfield code.)
- Have a letter prefix for pages in an appendix, for example, B-12. (Use the seq field code with the r switch and mergeformat.)
Things to Watch Out For
When working with Referenced Documents there are several things that you need to watch.- You can add a path to the RD code, for example, {RD C:\\test\\mydoc.doc}. Note the double backslashes.
- Network paths may not work. In this case omit the path and put the filename in quotes, for example, {RD "mydoc.doc"}. With this method you MUST make sure that the folder containing the files is the current folder. To ensure this is the case, open and close one of the documents just before pressing F9 to update fields. If you don't do this you may well see the following, rather unfriendly, error message:
This shows the folder that is currently active (Z:\Test_Training).
- Enclose long filenames containing spaces in double quotes. You must enclose long filenames containing spaces in double quotes, for example, {RD "C:\\test files\\test doc.doc"}.
- Filenames must be exactly right. Having an incorrect filename (or path) is be most likely reason for failure.
- A document can only have one TOC field. If your TOC fails to build you have probably either entered the referenced filename incorrectly or your machine is pointing to the wrong directory. Fix the problem and don't be tempted to insert another TOC.
- CONTENTS as a heading. If you want to have CONTENTS as a heading on the TOC page, remember that it will be picked up in a standard TOC if you assign Heading 1 to it. If you don't want to include it in the TOC, use a different style, perhaps called something like ContentsHeading.