Results 1 to 3 of 3
  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's in XP (WordXP)

    hiya

    to update all in the TOC the process has changed in XP.
    1. you have to goto VIew Outline
    2. On the Outline toolbar> click on Update TOC button
    3. the dlg is displayed> click on Update entire table>click OK

    so I've had to amend my code accordingly to update all TOC's in a document. so the below works if theres only 1 TOC in the doc.

    Dim strWindowViewType As WdWindowType

    'get the active window view so we can set the window view after the code has completed
    strWindowViewType = ActiveWindow.View.Type

    'set a temporary position
    ActiveDocument.Bookmarks.Add Name:="temp", Range:=Selection.Range

    'change the view to MasterView as this allows you to update ALL in a TOC
    ActiveWindow.ActivePane.View.Type = wdMasterView

    WordBasic.UpdateTableOfContents

    'set the window view to orginial view
    ActiveWindow.View.Type = strWindowViewType

    'goto the temp position.
    If ActiveDocument.Bookmarks.Exists("temp") = True Then
    ActiveDocument.Bookmarks("temp").Select
    ActiveDocument.Bookmarks("temp").Delete
    End If

    however if theres more than 1 TOC of course it doesnt work -
    I've tried the following however only the page numbers update? or I get the message 'THe current document does not contain a table of contents. To create a table of contents, point to the reference on the Insert menu, and then click Index and Tables' - when I've actually have 2 TOC's in my doc.

    Dim strTOC As TableOfContents
    For Each strTOC In ActiveDocument.TablesOfContents
    strTOC.Update
    Next strTOC


    any ideas on how to update the entire TOC - ie heading styles + page numbers for all my TOCs in my doc?
    why are things getting so complicated? <shrug>
    many thanks Diana

  2. #2
    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's in XP (WordXP)

    i must be having one of those afternoons...i've worked it out cheers diana :-)

    Dim myTOC As TableOfContents
    For Each myTOC In ActiveDocument.TablesOfContents
    myTOC.UpdatePageNumbers
    myTOC.UseFields = True
    Next myTOC

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: code to update TOC's in XP (WordXP)

    Thanks for sharing your solution, it all helps other people who silently search and make use of the information.

    StuartR

Posting Permissions

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