Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting in TOC problem

Status
Not open for further replies.

funkytunaa

Technical User
Oct 9, 2005
116
AU
I have a vb code that inserts and deletes a couple of different pages then the entry for those pages into the TOC. All works ok for each page seperately, though when I use the code to insert more than one page, ie Intro then Summary page, the second insertion puts the TOC entry "inside" the bookmark for the first page. So when I go to delete the first page entry from the TOC, it takes the second page entry out with it.

I think what it is doing is when the first entry is put in, the entry is inserted at the very start of the TOC and anything that is put in after is just put inside those bookmark brackets.

Not sure if I am looking for a solution, I think I just need confirmation that this is what is happening??

Cheers


 
What could you tell without seeing your code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps, sorry:
What could [!]we[/!] tell without seeing your code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Why - apparently - are you doing manual TOC entries?

"the second insertion puts the TOC entry "inside" the bookmark for the first page"

TOC can either be done automatically (tied to the Style), or you can put in TOC entries (either manully or programatically). The first method is generally better.

If you use the first method, then it should not matter how many pages are inserted, or where they are located, as the TOC is updated to match the styles being used.

That being said, PHV is correct in that we can not really suggest anything until you post actual code, or give better details of what you are doing.

Gerry
 
Appologies, I'm pretty much over trundling through this script :)

Below I think is where I am going wrong, in that the script searches the sections to find the TOC and then sets the TOC section start and inserts the Introduction at the start of the TOC, any thing else added in the same way is inserted within the Introduction "Bookmark".

I've attached the full script if need be too.

Set TOCStart = TOCSection.Range
TOCStart.Collapse wdCollapseStart

ActiveDocument.AttachedTemplate.AutoTextEntries("IntroTOC").Insert _
Where:=TOCStart, RichText:=True

I would love to do just an automated TOC after every page insertion, but when I manually insert the TOC it only picks up one section. The other Sections which are numbered i, ii, iii and Appendix A,B etc aren't inserted into the TOC?The only thing that the TOC insertion grabs is the pages numbered 1, 2, etc.

Thanks for your help too!!!!
 
 http://www.funkytuna.net/insertintro.txt
I would love to do just an automated TOC after every page insertion, but when I manually insert the TOC it only picks up one section. "

And...you can.

Don't do a manual one.
Use Styles properly.
Do not use Selection.

Better yet would be to actually write out PRECISELY, EXACTLY, what it is you want to do.



Gerry
 
Once again apologies, got a lot going through the noggin.

What I want to do, is insert a page/section with some information on it and have that section appear in the TOC.

Simple I would have thought.

Cheers
 
Hi funkytunaa,

If you're using Heading Styles, then updating the TOC is as simple as telling Word to do so - no insertion of new TOC entries is required. If you document has only 1 TOC, the vba for this is:
Code:
ActiveDocument.TablesOfContents(1).Update


Cheers
[MS MVP - Word]
 
Ahh, got the style insertion into the TOC.

When it inserts though it puts it as page 1, 2 whereas on the styles the page numbering is i, ii etc. Is there a way to carry the numbering style to the TOC?

Cheers and thanks!
 
Hi funkytunaa,

That suggests the page #s aren't being managed by page # field formatting. The TOC will respect whatever page # field formatting has been applied.


Cheers
[MS MVP - Word]
 
This is totally true! You are a genius!

Got all that simplified now.

I'm working off a template that someone else created and they have put way too much crap in here to do simple things..I was dubious about deleting whole sections, but I have and everything is working a heap better. Thank you....


BUT! :)

I think this is the last thing? And something I should workout myself.
I now have the inserting page i and ii etc and it updates the TOC, The page number on page ii is continuing from page i, when I delete page i...I think you mat know where I am going...page ii still says ii.

Would it be something like If page i exists then reformat page ii to start at page i?

 
Hi funkytunaa,

Pages in Word are a fluid concept - amongst other things, they take their cue from the active printer driver. If done properly, deleting the content of one page or inserting a new page-worth of material simply means the page #s (as indicated by suitably-formatted page # fields) on all the later pages will update to reflect their new position. So, had your document conformed to these principles, the former page ii would now display page i and simple TOC update would reflect that change.

I hope the implication of what you're saying isn't that the pages are delineated by hard page breaks with manually-typed page number at the bottom of each page. Anyone who creates such a document deserves a good thrashing!


Cheers
[MS MVP - Word]
 
It's definately not a typed page number.

just when I delete the first section, the second section page number seems to keep continue page number from previous section, which is the TOC. TOC being set to "page 1" the section keeps "Page ii"

These niggly things are really annoying.

Just a note, I'm deleting sections, not pages too would that have something to do with it?

Thank you so much for the help too!!
 
Hi funkytunaa,

Deleting Sections does complicate things because, depending on how the headers & footers were configured, the remaining Sections could get the page # properties from the last preceding Section.


Cheers
[MS MVP - Word]
 
Hmm, well at least it's complicated.

I've tried doing an if statement which says if page ii is there then reformat the page numbering to start page numbering from 1 but that seems to crash word for some reason, so I can't even test possibilities with that.

Might be a tomorrow job I think when my brain clears.

Thank you, I appreciate your help a lot!



 
You have to understand a bit about how Word works with page numbering.

Page numbering is determined by the page numbering format of the Section. This is a little difficult to grasp I know, but page numbering has (in a sense) nothing to do with the pages themselves. Page numbering is a child object (property) of the Section.

Further, as macropod pointed out deleting Sections can get tricky, and many people get results that are, shall we say, unexpected.

Say you have three Sections (and assuming all Section have Same as previous = False), and in the header is:

In Section 1: "This is Section 1 and Page 1"
(page # format for the Section is 1, 2, 3...)

In Section 2: "This is Section 2 and Page 2"
(page # format for the Section is 1, 2, 3...)

In Section 3: "This is Section 3 and Page iii"
(page # format for the Section is i,ii,iii...)

If you delete Section 2 - thus having TWO Sections now - the headers will show:

In Section 1: "This is Section 1 and Page 1"
In Section 2: "This is Section 3 and Page ii"

This is non-intuitive. But that IS the way Word works, and has since even the DOS versions.

Thus great care is needed when deleting Sections.

Further, the TOC will show the page numbering as it is in the Section it is pointing to. So if a later Section switches from 1,2,3 to i,ii,iii then its TOC entries will show THAT.

Section 1 Heading 1................1
Yadda heading 2.................3
Section 2 heading 1................6
Blah heading 2..................9
Section 3 Heading 1...............xi
whatever heading 2............xiv

The above is very possible.

Gerry
 
Got it.
Each section has different header information.
I did an if statement saying if "page i" section isn't there then do this.
ActiveDocument.Sections(N).Footers(wdHeaderFooterPrimary).PageNumbers.RestartNumberingAtSection = True

and when inserting the "page i" section, change it to false.
"N" is the "page ii" section number reference.

All good! Thanks so much for all your helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top