Results 1 to 15 of 15
  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Update TOC (Word 97SR2)

    Just a guess: no time to check. Is there a TablesOfContents(0)?
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    If there is it also returns

    "Member of the collection does not exist..."
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update TOC (Word 97SR2)

    I'd like to update 2 tables of contents. In field code format they look like this:

    1: { TOC O "1-3" } -- the standard "use headings" toc

    2: { TOC c "Figure" } -- the standard "table of figures"

    Both were created using the Word menu (Insert>Indexs and Tables).

    As I make changes to the document (add new headings or
    insert new figures), I'd like the TOCs to automatically
    update. It seems the only way to update them is to re-insert
    them.

    By using code, I can get #1 to update:

    ActiveDocument.TablesOfContents(1).Update

    But

    ActiveDocument.TablesOfContents(2).Update

    returns "Member of the collection does not exist".

    Do I not have 2 TOCs from Word's perspective? What do I have then? And how come F9 does not update the TOC fields?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    I answered one of the questions myself.

    No I don't have 2 TOCs. I have one TOC and one TOF (table of figures). Go figure.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Update TOC (Word 97SR2)

    F9 works fine to update TOCs and TOFs for me. Whenever the field trys to update I have to answer the question - Do I want to update the numbers or rebuild? If I have moved/added headings around the answer is to rebuild.

    Are you sure the fields are selected when you press F9? The only other possibility is that you have locked the field and therefore it won't update until you unlock it.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Los Angeles, California, USA
    Posts
    289
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    Andrew, Kevin PM'd me because I deleted my post which says essentially what yours does (because I thought I was wrong), and here's his question:

    "Yes, do re-post. But when I press F9 with the cursor in the TOC or TOF, the screen flickers and that's it. I do get a prompt if the cursor is in the TOC and I Insert>Indexes and Tables from the menu."

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    Very strange. 'Cause it don't work like that for me. The cursor is in the TOC field (I have even selected the entire field) then press F9 -- the status bar flashes something to fast to read, the screen flickers and nothing.

    If I have locked the field it is by accident 'cause I don't know how to lock fields -- via the UI or code.

    If the cursor is in the field and I Insert>Indexes and Table from the menu again, I get a prompt "Do you want to replace the existing table of contents?"

    Thanks, Andrew. I'll have to investigate this.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Update TOC (Word 97SR2)

    Can you right click the TOC and choose to update the field?
    The online help tells me
    - To lock a field and prevent changes to the current field results, click the field, and then press CTRL+F11.
    - To unlock a field and allow updates, click the field, and then press CTRL+SHIFT+F11.

    > The status bar flashes
    Odd, maybe you could slow it down by duplicating the content so the file is huge. That might give you time to read the message.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    I use the following macro assigned to an icon on my custom toolbar:

    Sub TOCUpdate()
    If ActiveDocument.TablesOfContents.Count >= 1 Then
    ActiveDocument.TablesOfContents(1).Update
    End If
    End Sub

  10. #10
    Lounger
    Join Date
    Nov 2001
    Location
    SF Bay Area
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    One other suggestion -- make sure that under Tools/Options, Print tab, that Update Fields is checked. Then the tables will automatically update whenever you print OR use Print Preview.

    Christie

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    Would you happen to know the VBA syntax that produces the dialog you refer to here? The "Update Numbers or Rebuild entire table" dialog...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Update TOC (Word 97SR2)

    Dialogs(wdDialogUpdateTOC).Show
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    Excellent. Thanks. How did you find this? I have the list from the VBA help and that one's not on there.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  14. #14
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Update TOC (Word 97SR2)

    Well... I did it by cheating. I'm using Word 2000 and I went into the VBA help and searched the "Built-in dialog box argument lists" and found it down the bottom.

    Naturally, this list is incomplete and there are other dialogs that exist in Word but weren't considered bullet-proof enough or valuable enough for the codies to make accessible (other than knowing it was there and what its number was). There was code here once upon a time where you could get to see ALL the dialogs built into Word. Its mighty useful sometimes as those dialogs can provide other functionality. I have kept it somewhere if you are interested.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  15. #15
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Update TOC (Word 97SR2)

    Hi Kevin:
    I use a macro (written by someone else, of course) to update all fields in my document:

    <pre>Public Sub UpdateAllFields()
    '---------------------------------------------------------------------------------------
    ' Procedure : sUpdateFields
    ' DateTime : 20-Dec-2001
    ' Author : Bryan Carbonnell
    ' Purpose : To update all fields in the Word Doucument
    ' including TOC, TOA, TOF and Fields in Headers/Footers
    '---------------------------------------------------------------------------------------

    Dim doc As Document ' Pointer to Active Document
    Dim wnd As Window ' Pointer to Document's Window
    Dim lngMain As Long ' Main Pane Type Holder
    Dim lngSplit As Long ' Split Type Holder
    Dim lngActPane As Long ' ActivePane Number
    Dim rngStory As Range ' Range Objwct for Looping through Stories
    Dim TOC As TableOfContents ' Table of Contents Object
    Dim TOA As TableOfAuthorities 'Table of Authorities Object
    Dim TOF As TableOfFigures 'Table of Figures Object

    ' Set Objects
    Set doc = ActiveDocument
    Set wnd = ActiveDocument.ActiveWindow
    ' get Active Pane Number
    lngActPane = wnd.ActivePane.Index
    ' Hold View Type of Main pane
    lngMain = wnd.Panes(1).View.Type
    ' Hold SplitSpecial
    lngSplit = wnd.View.SplitSpecial
    ' Get Rid of any split
    wnd.View.SplitSpecial = wdPaneNone
    ' Set View to Normal
    wnd.View.Type = wdNormalView

    ' Loop through each story in doc to update
    For Each rngStory In doc.StoryRanges
    If rngStory.StoryType = wdCommentsStory Then
    Application.DisplayAlerts = wdAlertsNone
    ' Update fields
    rngStory.Fields.Update
    Application.DisplayAlerts = wdAlertsAll
    Else
    ' Update fields
    rngStory.Fields.Update
    End If
    Next

    ' Loop through TOC and update
    For Each TOC In doc.TablesOfContents
    TOC.Update
    Next

    ' Loop through TOA and update
    For Each TOA In doc.TablesOfAuthorities
    TOA.Update
    Next

    ' Loop through TOF and update
    For Each TOF In doc.TablesOfFigures
    TOF.Update
    Next

    ' Return Split to original state
    wnd.View.SplitSpecial = lngSplit
    ' Return main pane to original state
    wnd.Panes(1).View.Type = lngMain
    ' Active proper pane
    wnd.Panes(lngActPane).Activate
    ' Close and release all pointers
    Set wnd = Nothing
    Set doc = Nothing

    End Sub</pre>


    Hope you find it useful.

Posting Permissions

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