1

I have the table of contents code below. I need to put this on the second page of my document. The document is 15 pages long. To insert it on the second page, i will have to add a page break at the end of the 1st page, and then have the table of contents insert on the second page.

How can I put it on the second page of the document? I know its something with range, but I'm note sure how to do that.

The code for the table of contents is below.

object oTrueValue = true;
        object start = oWord.ActiveDocument.Content.End - 1;

        Word.Range rangeForTOC = oDoc.Range(ref start, ref oMissing);
        Word.TableOfContents toc = oDoc.TablesOfContents.Add(rangeForTOC, ref oTrueValue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrueValue);
        toc.Update();

        Word.Range rngTOC = toc.Range;
        rngTOC.Font.Size = 12;
        rngTOC.Font.Name = "Arial";
        rngTOC.Font.Bold = 0;
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
sharpiee
  • 55
  • 4
  • 11

1 Answers1

1

Go to the end of the first page, then add a page break, and then a ToC:

// Go to end of document
Object what = WdGoToItem.wdGoToLine;
Object which = WdGoToDirection.wdGoToLast;
wordApp.Selection.GoTo(what, which, ref missing, ref missing);  

Insert a page break:

`selection.TypeText("\f");//page break`

Create ToC:

selection.Font.Bold = 1;
selection.TypeText("Table of Content\n");
TableOfContents toc = wordDoc.TablesOfContents.Add(selection.Range, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}//if
user3165438
  • 2,631
  • 7
  • 34
  • 54