Group:  Microsoft Word ยป microsoft.public.word.vba.userforms
Thread: Build TOC

Geek News

Build TOC
"Greg Maxey" <gmaxey[ at ]mIKEvICTORpAPAsIERRA.oSCARrOMEOgOLF> 12/13/2008 6:15:21 PM
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.

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org



Re: Build TOC
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/14/2008 8:46:58 AM
How about

With Selection.Fields
.Add Selection.Range, wdFieldTOC, "\f \h \z", False
.Update
End With
ActiveWindow.View.ShowFieldCodes = False

?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Greg Maxey wrote:
[Quoted Text]
> 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.


Re: Build TOC
"Greg Maxey" <gmaxey[ at ]mIKEvICTORpAPAsIERRA.oSCARrOMEOgOLF> 12/14/2008 2:56:32 PM
Graham,

Yes that works, thanks.

The root question, I suppose, is if your can preset the TOC options "Use
Outlining levels" and "Table entry fields" using VBA code:

Sub InsertManualTOC()
With Dialogs(wdDialogInsertTableOfContents)
.UseOutlineLevel = 0
.Fields = 1
.Show
End With
End Sub

Why can't you preset the "Styles" options. Sometimes I have a need to
build TOCs from a combination of styles and TC fields and sometimes I need
to build a TOC with just TC fields. The current behaviour of the TOC
Options dialog is "Styles" and "Use outline level" are preset to "checked"
and these value stick. Each time I want to create a TOC with a combination
of styles and fields I have to change the options but they won't stick. I
wanted to create a macro that opens the dialog with the Styles and fields
preset to "checked" and anther macro that opens the dialog with just fields
checked.

Can't find a way :-(



--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org


"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> wrote in message
news:uGtHDicXJHA.5764[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text]
> How about
>
> With Selection.Fields
> .Add Selection.Range, wdFieldTOC, "\f \h \z", False
> .Update
> End With
> ActiveWindow.View.ShowFieldCodes = False
>
> ?
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
>
> Greg Maxey wrote:
>> 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()
>> With Dialogs(wdDialogInsertTableOfContents)
>> .UseOutlineLevel = 0
>> .Fields = 1
>> .Show
>> End With
>> End Sub
>>
>>
>> Anyone have any ideas?
>>
>> Thanks.
>
>


Re: Build TOC
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/14/2008 3:26:16 PM
The short answer is that I don't know - it is much the same inserting form
fields and setting the parameters with vba to (say) a date format.
However for TOC basically all you have is a TOC field with an assortment of
switches. You can add those switches, if you know what they are (and they
are easy enough to establish by inserting the field from the insert > field
command) in the text segment of the Field.Add command - as in the example I
suggested.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Greg Maxey wrote:
[Quoted Text]
> Graham,
>
> Yes that works, thanks.
>
> The root question, I suppose, is if your can preset the TOC options
> "Use Outlining levels" and "Table entry fields" using VBA code:
>
> Sub InsertManualTOC()
> With Dialogs(wdDialogInsertTableOfContents)
> .UseOutlineLevel = 0
> .Fields = 1
> .Show
> End With
> End Sub
>
> Why can't you preset the "Styles" options. Sometimes I have a need
> to build TOCs from a combination of styles and TC fields and
> sometimes I need to build a TOC with just TC fields. The current
> behaviour of the TOC Options dialog is "Styles" and "Use outline
> level" are preset to "checked" and these value stick. Each time I
> want to create a TOC with a combination of styles and fields I have
> to change the options but they won't stick. I wanted to create a
> macro that opens the dialog with the Styles and fields preset to
> "checked" and anther macro that opens the dialog with just fields
> checked.
> Can't find a way :-(
>
>
>
>
> "Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> wrote in message
> news:uGtHDicXJHA.5764[ at ]TK2MSFTNGP04.phx.gbl...
>> How about
>>
>> With Selection.Fields
>> .Add Selection.Range, wdFieldTOC, "\f \h \z", False
>> .Update
>> End With
>> ActiveWindow.View.ShowFieldCodes = False
>>
>> ?
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>>
>> Greg Maxey wrote:
>>> 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()
>>> With Dialogs(wdDialogInsertTableOfContents)
>>> .UseOutlineLevel = 0
>>> .Fields = 1
>>> .Show
>>> End With
>>> End Sub
>>>
>>>
>>> Anyone have any ideas?
>>>
>>> Thanks.


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net