Creating a Table of Contents Involving Multiple Documents

by Allen Wyatt
(last updated January 27, 2017)

5

Francis has multiple documents that, for the purposes of a Table of Contents, he needs to treat as a single document. He wonders if there is a way to create a Table of Contents that actually spans multiple documents.

There are actually three ways to go about this. I'll quickly describe two of the approaches and then spend a bit more time on the third.

The first approach is to simply create a new document and then copy the contents of each of your files into that new document, in the proper order. Let's say that you have a series of documents named Chap01, Chap02, Chap03, and on through Chap32. You would open each of these files, in turn, press Ctrl+A to select everything in the file, switch to the new document, and press Ctrl+V. As you do this, the new document gets larger and larger (of course), but when completed you can easily add a TOC to the beginning of the document.

Quite honestly, that approach is a lot of work, and it isn't terribly flexible. Every time you edit one of the documents you need to repeat the process to get a new TOC. So, I wouldn't recommend this particular approach.

The second approach is to use a master document and subdocuments. This is a feature built into Word that allows you to define a "container document" (the master document) and identify other documents that should be included in the container (the subdocuments). To create a master document, follow these steps:

  1. Create a brand new document. Make sure that it uses the same template as the documents you want included in the TOC.
  2. Display the document in Outline view. (Display the View tab of the ribbon and click the Outline tool in the Views group.)
  3. Make sure the Outlining tab of the ribbon is displayed. (It should be displayed by default when you switch to Outline view.)
  4. In the Master Document group, click the Show Document tool. Word expands the tools in the Master Document group.
  5. Click the Insert tool, which is visible in the Master Document group. Word displays the Insert Subdocument dialog box. (This dialog box looks very similar to a standard Open dialog box.)
  6. Using the controls in the dialog box, locate and select the first document you want included in your TOC.
  7. Click Open. Word inserts the contents of the document, surrounded by section breaks.
  8. Repeat steps 5 through 7 for each of the other documents you want included.
  9. Insert and generate your TOC as you normally would.

If you decide to use this approach (creating a master document), understand that there are numerous horror stories related to their use. Many people consider master documents to be the fastest available way to Word document corruption. Because this is a possibility, you'll want to make sure you protect yourself by keeping backup copies of all of your original documents without those backups being part of a master document. You can find more information about corruption of master documents at this page on the Word MVP site:

http://wordmvp.com/FAQs/General/WhyMasterDocsCorrupt.htm

The third approach is to use field codes to combine the documents into a single document. This approach has the fewest number of drawbacks that I can find, so it is the one that I would suggest. Follow these steps:

  1. Create a brand new document. Make sure that it uses the same template as the documents you want included in the TOC. You should make sure the insertion point is at the beginning of the document.
  2. Display the Insert tab of the ribbon.
  3. Click the Quick Parts tool in the Text group. Word displays some choices below the tool.
  4. Click Field. Word displays the Field dialog box.
  5. Choose Indexes and Tables from the Categories list (top left corner of the dialog box). (See Figure 1.)
  6. Figure 1. The Field dialog box.

  7. Select RD from the Field Names list. Word adjusts the appearance of the dialog box to include a Filename or URL box.
  8. In the Filename or URL box enter the name of the first file you want included in the TOC.
  9. Click OK. Word inserts the field into the document.
  10. Press Enter once.
  11. Repeat steps 2 through 9 for each of the other documents you want included.
  12. Insert and generate your TOC as you normally would.

Even though the RD field-code route is the safest approach, understand that if you are using Word 2013 you may experience a bug in the implementation of RD codes. You'll know if you've encountered the bug if the generated page numbers for a file are all the same. You can apparently work around the bug by having all of the referenced files open in Word when you generate (or regenerate) the TOC. You could also, if desired, change all the RD field codes to INCLUDETEXT field codes, but if you choose to do so you will need to put a section break before and after each of the field codes.

If you want some additional information on using this third approach, check out these resources:

http://mousetrax.com/mastdoc.html

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3318) applies to Microsoft Word 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Selecting a Custom Chart

Microsoft Graph allows you to easily create charts from numeric data, without the need to use Excel. Here's how to use Graph ...

Discover More

Drop-Down List Font Sizes

Excel has several features that cannot be customized. The font size in the drop-down lists is one of them. If you need make ...

Discover More

Selecting a Specific Cell in a Macro

Need to use a macro to select a specific cell in a different workbook? It's not as straightforward of a proposition as you ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Problems with TOC Styles

If you generate a table of contents for your document, there may be some unexpected surprises in the way the TOC appears. ...

Discover More

Creating a TOC that Includes Specific Styles

Want to create a special TOC that contains different elements of your document? It's easy to do if you consistently use ...

Discover More

Specifying a Table of Contents Entry

If you need to create a specialized table of contents, you need to know how to add TOC entries to your document. It's easy to ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 4 + 1?

2017-07-24 19:46:41

Rika

Is the RD field version limited to 7 documents? I can't seem to add anything after Chapter 7.


2017-02-17 02:59:22

Tara

Can this also be done with a table of authorities (putting it in a separate document than the one containing the marked cites)?


2016-12-29 13:56:55

Gordon M

Just as an update, I had the same bug in Word 2013, but eventually it was fixed in a Word update (I think some time in 2014 or 2015). Word 2016 also does not have this issue.

Using the RD method, is there any way to create a PDF file of the final document (with all the documents included), and for that PDF to include hyperlinks from all the TOC entries to the correct locations in the PDF?


2015-10-03 04:45:15

Ken Endacott

The macro:
Sub MultipleFilesTOC()
Dim fl As String
Dim flNames() As String
Dim flCount As Long
Dim j As Long
Dim k As Long
Dim TOClevels As Long
Dim mydir As String
Dim aString As String
Dim projName As String
Dim fldType As Long

' ----- Delete any existing TOC and RD fields -----
j = ActiveDocument.Fields.Count
If j > 0 Then
For k = j To 1 Step -1
fldType = ActiveDocument.Fields(k).Type
If fldType = wdFieldTOC Or fldType = wdFieldRefDoc Then ActiveDocument.Fields(k).Delete
Next k
End If

' ----- set generic name to current file name -----
projName = ActiveDocument.Name
mydir = ActiveDocument.Path
TOClevels = 3

' ------ get list of files in directory ------
j = InStr(projName, ".")
aString = Left(projName, j - 1) & "*" & Mid(projName, j)
flCount = 0
ReDim flNames(0)
fl = Dir(mydir & "" & aString)
Do While fl <> ""
If UCase(fl) <> UCase(ActiveDocument.Name) Then
flCount = flCount + 1
ReDim Preserve flNames(flCount)
flNames(flCount) = fl
End If
fl = Dir()
Loop
If flCount = 0 Then
MsgBox "No files found"
Exit Sub
End If

' ----- sort file names -----
For j = 1 To UBound(flNames) - 1
For k = j + 1 To UBound(flNames)
If flNames(j) > flNames(k) Then
fl = flNames(j)
flNames(j) = flNames(k)
flNames(k) = fl
End If
Next k
Next j

' ----- Create TOC and RD fields -----
Selection.Fields.Add _
Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False, _
Text:="TOC o " & Chr(34) & "1-" & Trim(Str(TOClevels)) & Chr(34) & " h z u"
For j = 1 To UBound(flNames)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False, _
Text:="RD " & Chr(34) & flNames(j) & Chr(34) & " f"
Next j
ActiveDocument.TablesOfContents(1).Update
ActiveWindow.View.ShowFieldCodes = False
End Sub


2015-10-03 04:36:41

Ken Endacott

The fourth approach is to use a macro to generate the TOC and RD fields.

This following macro will create a Table of Contents from several documents having the same generic name. The TOC will be created in the current document after deleting any existing TOC and RD fields.

1. Give documents generic names for example MydocChapt01, MydocChapt02 etc. They must be in the same folder.
2. Adjust page numbering in the documents to give number spanning.
3. The front document should have the generic name in this case Mydoc. It may for example contain the title page and summary and can include heading paragraphs.
4. Set the variable TOClevels to give the number of levels in the TOC.
5. Position the cursor at the position where you want the TOC and run the macro

THE POSTING SOFTWARE IS PREVENTING ME FROM INCLUDING THE MACRO LISTING


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.