Update TOC

G

Greg Maxey

Sub Macro1()
ActiveDocument.TablesOfContents(1).UpdatePageNumbers
End Sub

Macro 1 updates the page numbers of a TOC and leaves the descriptive text
unchange. This is expected.


Sub Macro2()
ActiveDocument.TablesOfContents(1).Update
End Sub

Macro 2 does nothing. I would expect that it would update the entire TOC.

Using Word 2003. The only way I can figure out how to update the entire TOC
is with the Update TOC menu item on the Outlining toolbar. Even with this
method I always have to answer a prompt.

What is the VBA code to just update the entire table without the prompt?

Thanks
 
G

Greg Maxey

Anne,

Are you using Word2003? Here are my results again following your repsonse:

Sub Macro()
ActiveDocument.TablesOfContents(1).Update
End Sub

Nothing happens
 
G

Greg Maxey

Still duck eggs. The problem appears to be in my VB Editor. I am in deep
water here and hardly know what I am talking about. However, if I add a
second TOC and run this code:

Sub MacroTest()
Dim i As Long
For i = 1 To ActiveDocument.TablesOfContents.Count
ActiveDocument.TablesOfContents(i).Update '****
Next
End Sub

And then step though, I get to the the line tagged **** and the macro just
terminates. For some reason the line of code is not being executed.

Is it OK if I start foaming at the mouth now :)
 
G

Greg Maxey

I think a contributing factor may be that I have two Office11 Object Library
references listed. I can uncheck one but not both. I can shutdown Word and
delete both files, but Office installer puts them both back on startup. I
have removed and reinstalled Office (in desperation) but still not joy.
 
R

Ron Barnes

Hi Greg,
I'm working on the same problem, but in Word97. UpdatePageNumbers doesn't
apper as an option. Do you know how to do this in code in Word97?
Thanks,
Ron Barnes
 
G

Greg

Ron,

Sorry no I don't. You might want to post a new thread asking your
specific question as it may not get much exposure buried here ;-)
 
G

Greg

Anne and anyone else following.

It appears I have stumbled on a cause of the problem yet still can't
understand it. As it turns out I was having the same problem at work
using Word2000. The only thing common with my work computer and home
computer is my Normal.dot

First I am guilty of sloppy housekeeping with my normal.dot (Any
suggestions for changing my ways are welcome.) I have about 10
different modules in my Normal.dot and probably a hundred or more
macros.

I created a new Normal.dot and all worked as expected.

Next exported all of my modules from the NormalOld.Dot to the desktop.

Next I imported the modules into the new normal.dot one at a time
checking functionality of the TOC update each time. The problem
reoccurred when I imported one of the modules.

I started looking at the individual macros in that module. I found
that the following macro was causing the behavior:

'Sub UpdateFields()
'Dim oStory As Range
' For Each oStory In ActiveDocument.StoryRanges
' oStory.Fields.Update
' If oStory.StoryType <> wdMainTextStory Then
' While Not (oStory.NextStoryRange Is Nothing)
' Set oStory = oStory.NextStoryRange
' oStory.Fields.Update
' Wend
' End If
' Next oStory
'Set oStory = Nothing
'End Sub

When I stetted in out as show above the first time I ran the TOC update
routine I got and Error something like "Could not find sub or funtion).
It was like the line
ActiveDocument.TablesofContents.Update was trying to run the
UpdateFields() routine above. I close the VBE and reopened it and the
TOC routine then ran fine. I have since renamed the macro above as
myUpdateFields all is working properly at least on the Word2000 PC.
 
R

Ron B via OfficeKB.com

Greg,

I found a way to make it work. I had entered the command in the subprocedure
that creates the Table. When I moved it out of that sub, it works.
Thanks,
Ron
 

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