Build TOC

G

Greg Maxey

Sorry for the posting in the Userform group ;-(

I have some requirements to build TOCs using strictly TC fields (no styles).

I can do that easy enough by clicking on the InsertTOCdialog, clicking on
Options, and changing the Build table of contents from options 1. Uncheck
"Styles" 2. Uncheck "Outline levels" and 3. Check "table entry fields"

I want to do this programmatically. I have figured out how to uncheck
"Outline levels" and how to check "table field entries" but can find no way
to uncheck "Styles"

Sub InsertManualTOC()
Dim i As Long
Dim myArray() As String
With Dialogs(wdDialogInsertTableOfContents)
.UseOutlineLevel = 0
.Fields = 1
.Show
End With
End Sub


Anyone have any ideas?

Thanks.
 
J

Jay Freedman

Sorry for the posting in the Userform group ;-(

I have some requirements to build TOCs using strictly TC fields (no styles).

I can do that easy enough by clicking on the InsertTOCdialog, clicking on
Options, and changing the Build table of contents from options 1. Uncheck
"Styles" 2. Uncheck "Outline levels" and 3. Check "table entry fields"

I want to do this programmatically. I have figured out how to uncheck
"Outline levels" and how to check "table field entries" but can find no way
to uncheck "Styles"

Sub InsertManualTOC()
Dim i As Long
Dim myArray() As String
With Dialogs(wdDialogInsertTableOfContents)
.UseOutlineLevel = 0
.Fields = 1
.Show
End With
End Sub


Anyone have any ideas?

Thanks.

Hi Greg,

I think this is a case where dealing with the dialog will just drive you nuts.
It'll be easier to build the TOC field directly.

The default from the dialog (with styles and outline levels, and not fields)
inserts the field

{TOC \o "1-3" \h \z \u}

The \o switch turns on the use of heading styles, and the \u switch turns on the
use of outline levels.

The field inserted by the dialog without styles or outline levels, but with TC
fields, is

{TOC \f \h \z}

where the \f switch turns on the use of TC fields. (The \h switch is for
hyperlinking, and \z suppresses leaders and page numbers in Web layout view.)

Sample code:

Dim oRg As Range
Set oRg = ActiveDocument.Range
oRg.Collapse wdCollapseEnd

With ActiveDocument.Fields
.Add Range:=oRg, Type:=wdFieldTOC, Text:="\f \h \z"
.Update
End With
 
G

Greg Maxey

Jay,

Thanks. I can probably make that work.



Jay said:
Hi Greg,

I think this is a case where dealing with the dialog will just drive
you nuts. It'll be easier to build the TOC field directly.

The default from the dialog (with styles and outline levels, and not
fields) inserts the field

{TOC \o "1-3" \h \z \u}

The \o switch turns on the use of heading styles, and the \u switch
turns on the use of outline levels.

The field inserted by the dialog without styles or outline levels,
but with TC fields, is

{TOC \f \h \z}

where the \f switch turns on the use of TC fields. (The \h switch is
for hyperlinking, and \z suppresses leaders and page numbers in Web
layout view.)

Sample code:

Dim oRg As Range
Set oRg = ActiveDocument.Range
oRg.Collapse wdCollapseEnd

With ActiveDocument.Fields
.Add Range:=oRg, Type:=wdFieldTOC, Text:="\f \h \z"
.Update
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top