Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

Update TOC

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 14 Sep 2005 23:28 GMT
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

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Anne Troy - 15 Sep 2005 01:22 GMT
Hi, Greg. I just created a sample file, and Macro2 most indeededly updated
the Table of contents, both for content and page numbering.
************
Anne Troy
www.OfficeArticles.com

> Sub Macro1()
>  ActiveDocument.TablesOfContents(1).UpdatePageNumbers
[quoted text clipped - 16 lines]
>
> Thanks
Greg Maxey - 15 Sep 2005 01:42 GMT
Anne,

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

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

Nothing happens

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi, Greg. I just created a sample file, and Macro2 most indeededly
> updated the Table of contents, both for content and page numbering.
[quoted text clipped - 27 lines]
>> http://gregmaxey.mvps.org/word_tips.htm
>> For some helpful tips using Word.
Anne Troy - 15 Sep 2005 01:45 GMT
I've got all 4 versions running here, and specifically testing your macro in
2003, yes. :)
************
Anne Troy
www.OfficeArticles.com

> Anne,
>
[quoted text clipped - 38 lines]
>>> http://gregmaxey.mvps.org/word_tips.htm
>>> For some helpful tips using Word.
Anne Troy - 15 Sep 2005 01:46 GMT
PS: If you want me to test on an actual file, just email it.
************
Anne Troy
www.OfficeArticles.com

> Anne,
>
[quoted text clipped - 38 lines]
>>> http://gregmaxey.mvps.org/word_tips.htm
>>> For some helpful tips using Word.
Greg Maxey - 15 Sep 2005 02:00 GMT
On the way (provided I picked the right address).  Thanks.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> PS: If you want me to test on an actual file, just email it.
> ************
[quoted text clipped - 49 lines]
>>>> http://gregmaxey.mvps.org/word_tips.htm
>>>> For some helpful tips using Word.
Anne Troy - 15 Sep 2005 02:11 GMT
"Anybody" at that site gets to me. :)
************
Anne Troy
www.OfficeArticles.com

> On the way (provided I picked the right address).  Thanks.
>
[quoted text clipped - 51 lines]
>>>>> http://gregmaxey.mvps.org/word_tips.htm
>>>>> For some helpful tips using Word.
Greg Maxey - 15 Sep 2005 02:38 GMT
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 :-)

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> "Anybody" at that site gets to me. :)
> ************
[quoted text clipped - 62 lines]
>>>>>> http://gregmaxey.mvps.org/word_tips.htm
>>>>>> For some helpful tips using Word.
Greg Maxey - 15 Sep 2005 05:29 GMT
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.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> 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
[quoted text clipped - 78 lines]
>>>>>>> http://gregmaxey.mvps.org/word_tips.htm
>>>>>>> For some helpful tips using Word.
Greg - 15 Sep 2005 17:38 GMT
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.
Ron Barnes - 15 Sep 2005 16:04 GMT
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

> Sub Macro1()
>   ActiveDocument.TablesOfContents(1).UpdatePageNumbers
[quoted text clipped - 16 lines]
>
> Thanks
Greg - 15 Sep 2005 16:37 GMT
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 ;-)
Ron B - 15 Sep 2005 19:08 GMT
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

>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 ;-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.