TOC Update - Inconsistent

R

RWN

Wd97/NT4 & Wd2k/Win2kPro
(having my share of problems!)

Sub LocTOC()
If ActiveWindow.ActivePane.View.ShowAll Then
ActiveWindow.ActivePane.View.ShowAll = False
ActiveDocument.TablesOfContents(1).Update
'ActiveDocument.TablesOfContents(1).UpdatePageNumbers
End Sub

After text (Auto Text as well as InsertFile) added this routine is
called.
The 1st statement ensures that the hidden text is not displayed (using a
hidden paragraph mark to get run-in headings).
Updates table entries ok but sets all page #'s as "1" on display.
Clicking on the page # does take me to the actual page however.
Ok when "Print View" and printed. Also corrects itself if manually
updating table/page numbers.
Even tried calling for "Update" AND UpdatePageNumbers" (hence the rem'd
statement), no go.
The major problem I'm having is that it is intermittent.
Under the same scenarios (same AutoText or InsertFile addition) it will
sometimes work and sometimes not.
Tried scrolling etc. to see if it was a refresh problem, but it stayed
the same.

Any ideas?
 
P

Peter Hewett

Hi RWN

Try calling the Update method twice:
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.TablesOfContents(1).Update

I normally work with the TOC field object and use something like this to do the TOC
update:

Public Sub UpdateTOC()
Dim fldTOC As Word.Field
Dim boolFound As Boolean

' Find the TOC field to update
For Each fldTOC In ActiveDocument.Fields
If fldTOC.Type = wdFieldTOC Then
boolFound = True
Exit For
End If
Next

' Update the TOC
If boolFound Then
fldTOC.Update
fldTOC.Update
End If
End Sub

HTH + Cheers - Peter
 
R

RWN

Peter;
Thanks for the suggestion.
I'll try it tomorrow at work (Wd'97). It's been working fine this
evening at home (Wd2k) - which figures!

Excuse my ignorance, I don't usually work in Word (mostly xl), but I'm
assuming that "fldTOC" represents an entire Table Of Contents (vs. one
entry-or what I think of as a field)?

Thanks for your time.
 
P

Peter Hewett

Hi RWN

There are a number of objects in Word that are represented by fields in the document yet
belong to other collections as well. Mostly when I work with TOC's it's to reformat them
in ways not supported by Word as standard so I tend to work with the field rather than the
collection object (TablesOfContents). So you're right the object variable fldTOC
represents the entire TOC (if boolFound is True). A TOC is a peculiar construct that in
turn is made up of numerous other fields. Each line of the TOC contains a
Hyperlink/PageRef field pair or just a PageRef field.

You can compile a TOC from a number of sources Styles, Outline levels or TC fields. TC
fields are not to be confused with TOC fields. A TC field represents an entry that will
be added to a TOC. The TOC field represents the TOC proper.

HTH + Cheers - Peter
 
R

RWN

Thanks for the explanation-especially the "TC" portion.

BTW, I couldn't duplicate the original situation today at work. I hate
when that happens-darned difficult to fix something that ain't broke all
the time!
However, I know that as soon as I put it in production it'll pop up
again!
 

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