View Single Post
 
Old 07-01-2016, 04:11 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code doesn't work the way it should because it doesn't correspond to the way that Word works.
Looking at each line, this is where you are having problems

Line 1 produces a field code that looks like this
TOC \o "1-9" \h \z \t "Heading 1,Heading 2"
So your Heading 1 and Heading 2 entries appear in the TOC because of the \o "1-9" part. Using the \t switch is superfluous in this case because those two styles are already in there. Also "Heading 1,1,Heading 2,2" is what is supposed to be in the quotes - you have to tell Word what TOC style to assign to each style.

Line 2 doesn't align with how tab leaders work.
.TablesOfContents(1).TabLeader = wdTabLeaderDots
A tab leader is a property of a particular tab in a particular paragraph or style. In the context of an entire table of contents which could contain 9 styles and many paragraphs this line means nothing. Plus the first table of contents in a document may not actually BE the TOC that you just inserted in the first line (if there is another TOC earlier in the doc).

Line 3
.TablesOfContents.Format = wdIndexIndent
I have no idea of what you expected to happen with this line. wdIndexIndent is a built-in constant with a value of 0. What does it mean to set a "Format = 0" when Format might be typeface/font size/bold/italic/paragraph spacing/paragraph indent etc. And where are you trying to apply this 'formatting'?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote