Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating a TOC (Word2000/2002)

    Hi,

    I am trying to automate some document actions in Word2000/XP (I can choose the version...). I am doing this from Perl iso. VB/VBA, but the language is not really the problem. What I want to do is :
    1. Load a doc into word.
    2. Cut out some things between known delimiters
    3. Update the TOC/TOF
    4. Save the doc & exit.

    Actions 1,2 and 4 work like a charm. But I cannot get that freaking TOC to update ! No matter what I try, it will only update the page numbers in best cases. This is so frustrating :-( I used the macro recorder to see how it records a TOC update when choosing to update it completely iso. only the page numbers, but I noticed that it does not put that choice into the code... running the macro will only pop up the dialog box with that question again.

    I also tried most of TOC solutions posted here, but once again => page numbers updates and nothing more :-(

    Anyone knows the trick to make word update every single bit of the TOC ?

    Thanks !

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Updating a TOC (Word2000/2002)

    Welcome to Woody's Lounge!

    Try

    ActiveDocument.TablesOfContents(1).Update

    If you have created a variable of type Document, use that instead of ActiveDocument. If you have more than one TOC in the document, use the appropriate index number.

  3. #3
    New Lounger
    Join Date
    Feb 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating a TOC (Word2000/2002)

    "Welcome to Woody's Lounge!"

    Thanks ! :-)

    I tried the line of code you have there (well... translated to Perl then) but it gives me a Type Mismatch error from OLE...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Updating a TOC (Word2000/2002)

    I'm sorry, I have zero knowledge of Perl. Does it work for you if you try it in Word itself?

  5. #5
    New Lounger
    Join Date
    Feb 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating a TOC (Word2000/2002)

    Oh wait... now I tried :

    $Word->ActiveDocument->TablesOfContents(1)->Update();

    and this does work ! Although I do not know why... array indexes are supposed to be square brackets in Perl... Anyone that knows why a function call with argument = 1 returns met the first TOC (even though the function - well method) is documented as not taking any arguments, is very welcome to explain to me.

    Anyway : Thank you VERY VERY much for this answer... it works, oh yes it works...

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Updating a TOC (Word2000/2002)

    Don't confuse TableOfContents and TablesOfContents. According to the online help, TablesOfContents is "A collection of TableOfContents objects that represent the tables of contents in a document." You refer to an item in a collection by specifying its index number (or name).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •