PDA

View Full Version : Table of Contents Field Code



ABrown
03-31-2010, 03:57 AM
I wonder if anyone can help - I have been trying to modify a template that requires section headings to be centred, therefore I have to set the style so that there is no tab mark following the heading level, but when I run the table of contents I want the section heading to have a tab mark after the section number so there is a gap between that and the name of the section - ie:

In document:

(centred on top of page)
Section 1
Section 1 Heading

Then in the table of contents:

Section 1 (tab) Section 1 Heading ..............................Page number

What I am trying to get the code to do is put a tab mark after the first part of the text in the TOC field code.... I am not sure if this is possible.

I have limited VBA experience and wondered if someone more advanced could help?

What I really need is to search for the field code then move through each instance of section and add the tab (I think!).

Many thanks for any assitance.

Annette

fumei
03-31-2010, 08:28 AM
First of all, there is NO relationship between Section and Table of Contents.

The ToC is generated by whatever style you set for the ToC to use.

Please explain:

(centred on top of page)
Section 1
Section 1 Heading

The "Section 1" - above "Section 1 Heading" - is this text?

"I am not sure if this is possible. " It may or may not be.

ABrown
04-01-2010, 08:36 AM
Thanks - I am aware of that the styles are not related, but the bevaviour (ie centred) for the Section heading impacts the way the TOC works with regard to the tab mark after - the problem is I can't get the TOC style to give me the tab mark after the Section heading title in the TOC. The Section 1 is a field code (Heading 7 level) and the Section 1 Heading is the text (ie the Heading itself). I hope I have made that clearer, although it is a bit difficult to explain. I guess what I am asking is if it is possible to programmatically change the way a style works.

Thanks.

Annette

fumei
04-01-2010, 11:38 AM
" I guess what I am asking is if it is possible to programmatically change the way a style works."

Yes, but then it does exactly that. In other words, all instances of the styles are changed.

However, the style - i.e. the formatting - of a ToC is NOT the style of the Style it uses to generate.

Let me explain.

Say you have the ToC use the Syle "Myheading1" style (as opposed to the default Word style "Heading 1") to generate LEVEL 1 ToC entries.

Say "Myheading1" style has Font = Arial, 16 pts.

The ToC generates entries for all instances of "MyHeading1" paragraphs it finds. But it uses the TOC1 Style to format the ToC entry itself.

So if TOC1 has Font = TimesRoman, 12 pts, THAT is what is used in the ToC, not the format/structure of the styles it finds for entries.


"The Section 1 is a field code " What field code?

"but the bevaviour (ie centred) for the Section heading impacts the way the TOC works with regard to the tab mark after"

"Section heading " Actually...nope, there is no such thing. Sections do not have headings. YOU may make a specific paragraph a specific style and call it a Section heading, but Word does not.

I am still trying to follow what is actually happening. Please expand on the field code you say you are using.

macropod
04-03-2010, 12:36 AM
Hi Annette,

I suggest reinstating the tab character you've omitted from the Heading Style's numbering , and formatting the Heading Style's paragraph layout with a first line indent equivalent to the default tab width. That should achieve the visual effect you're after for both the heading and the TOC.

Paul_Hossler
04-03-2010, 06:12 AM
Is this close?

I used Heading 1 for the top of page Section X with a Tab and a New Line afterwards followed by the Section X Title text on the following line.

TOC picks up the entire paragraph

Heading 2 is the lower level headings, etc.

I can atach a sample doc if you want

Paul

Paul_Hossler
04-03-2010, 06:30 AM
The section number etc are hard coded, but fields, etc. would work the same

Since a picture is worth 1K words, this is the Tab-NewLine I was describing in the Heading 1 styled paragraphs

You still need to manually incude the tab and remember to use New Line, so maybe some one can come with a more automated approach

For me, I usually tend to try and use the Word formatting capabilities before I resort to VBA, but that's just me.

Paul