Results 1 to 11 of 11
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code to update TOC - get errors (WordXP SP3)

    I have code to up date the TOC, however when I run the code on the following lines I get the error msg 'Sub of Function not defined'

    on the lines :

    myTOC.Update

    ActiveDocument.TablesOfContents(1).Update


    Dim myTOC As TableOfContents
    For Each myTOC In ActiveDocument.TablesOfContents
    myTOC.Update
    myTOC.UpdatePageNumbers
    Next myTOC


    any ideas?
    dina

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    Hi Diana,

    From the order in which your code snippets are posted, it looks like:
    1. you're calling myTOC before it's been defined
    2. you're explicitly trying to update the first Table Of Contents. Obviously this will fail if your document doesn't yet have one.
    You'll also run into problems if 'Track Changes' is on when you update the TOC. See how you go with the following code:

    Sub UpdateAllTOCs()
    Dim TrkStatus As Boolean ' Track Changes status flag
    Dim myTOC As TableOfContents
    With ActiveDocument
    ' Store current Track Changes status, then switch off
    TrkStatus = .TrackRevisions
    .TrackRevisions = False
    ' Loop through TOCs and update
    For Each myTOC In .TablesOfContents
    myTOC.Update
    myTOC.UpdatePageNumbers
    Next
    ' Restore original Track Changes status
    .TrackRevisions = TrkStatus
    End With
    End Sub

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    Hi Macropod

    Apologies I may not have explained myself:

    when i was using the line of code to update TOC >
    ActiveDocument.TablesOfContents(1).Update

    The error msg displayed.

    I then rewrote the code to :

    Dim myTOC As TableOfContents
    For Each myTOC In ActiveDocument.TablesOfContents
    myTOC.Update
    myTOC.UpdatePageNumbers
    Next myTOC

    to see if this code worked, the result was i still was getting the error message.


    Ill try your code & see how it goes...
    many thanks
    diana

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    Hello

    i tried your code on line
    myTOC.Update

    i get the error msg 'Sub or Function not defined'

    diana

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    Does the error only affect one document or does it affect all documents? Does it depend on the number of TOCs in the document? If it only affects one document, see if there is a TOC in the document that has some kind of partial or invalid definition. (You could use Alt+F9 to display field codes and then search for TOC to find them, I think.)

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    the error is occuring on different types of documents.

    on these documnets there is always 1 TOC & if no TOC is detected, the code inserts a TOC in

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    Try a clean start (Start>Run> winword.exe /a) to rule out interference from global templates or other macros in Normal.dot. You will need to copy your TOC update code into a document or an attached template, or import or paste it into Normal.dot after you start clean.

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    the code below doesnt update my TOC. if I add a new paragraph with a heading style to be contained in the TOC > result still doesnt update?

    ActiveDocument.TablesOfContents(1).UpdatePageNumbe rs
    ActiveDocument.TablesOfContents(1).Update

    any ideas?
    diana

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

    Re: code to update TOC - get errors (WordXP SP3)

    It seems there is something wrong with your installation of Word. Try Phil Rabichow's <!post=Systematic Approach to Behavioral Problems in Word (97/2000),197827>Systematic Approach to Behavioral Problems in Word (97/2000)<!/post>.

    If that doesn't help, try Help | Detect and Repair (you'll probably need to have your Office CD at hand)

  10. #10
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: code to update TOC - get errors (WordXP SP3)

    Hi Diana,

    Just to be sure, make sure your Word installation has a Reference to the Word object library (in the VBE it's under Tools|References). At the very least, you should have references to:
    . VBA
    . OLE Automation
    . Word object library
    . Office object library (if office is installed)

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

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

    Re: code to update TOC - get errors (WordXP SP3)

    As far as I know, it's not possible to clear the reference to the Word object library. If it went missing for some reason, the code would refuse to start at all.

Posting Permissions

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