VBA to update TOC

Discussion in 'Word VBA Beginners' started by Steve Hodgson, Jan 25, 2010.

  1. I've written a very simple VB Word macro to update the tables of
    contents in a Word file but would like to extend this to include a
    table of tables.

    The document includes a Table each of Contents, Figures and Tables
    that I want to be able to updated without the need to hit <ctrl>-A, F9
    and then make the selection to update all table contents three times.

    The macro below works for contents and figures but not for tables. Is
    there a straightforward way to extend it to cover a table of tables
    which is defined by { TOC /T "TAB_TITLE" \C }.

    Sub Update_TOC()
    '
    ' Update_TOC Macro
    ' Macro created 20/01/2010
    '
    ActiveDocument.TablesOfContents(1).Update
    ActiveDocument.TablesOfFigures(1).Update
    End Sub
     
    Steve Hodgson, Jan 25, 2010
    #1
    1. Advertisements

  2. Steve Hodgson

    macropod Guest

    Hi Steve,

    Try something along the lines of:
    Sub UpdateRefTables()
    Dim TOC As TableOfContents ' Table of Contents Object
    Dim TOA As TableOfAuthorities ' Table of Authorities Object
    Dim TOF As TableOfFigures ' Table of Figures Object
    With ActiveDocument
    ' The following routines update TOC, TOA or TOF contents.
    ' Loop through Tables Of Contents and update
    For Each TOC In .TablesOfContents
    TOC.Update
    Next
    ' Loop through Tables Of Authorities and update
    For Each TOA In .TablesOfAuthorities
    TOA.Update
    Next
    ' Loop through Tables Of Figures and update
    For Each TOF In .TablesOfFigures
    TOF.Update
    Next
    End With
    End Sub

    --
    Cheers
    macropod
    [Microsoft MVP - Word]


    "Steve Hodgson" <> wrote in message news:...
    > I've written a very simple VB Word macro to update the tables of
    > contents in a Word file but would like to extend this to include a
    > table of tables.
    >
    > The document includes a Table each of Contents, Figures and Tables
    > that I want to be able to updated without the need to hit <ctrl>-A, F9
    > and then make the selection to update all table contents three times.
    >
    > The macro below works for contents and figures but not for tables. Is
    > there a straightforward way to extend it to cover a table of tables
    > which is defined by { TOC /T "TAB_TITLE" \C }.
    >
    > Sub Update_TOC()
    > '
    > ' Update_TOC Macro
    > ' Macro created 20/01/2010
    > '
    > ActiveDocument.TablesOfContents(1).Update
    > ActiveDocument.TablesOfFigures(1).Update
    > End Sub
     
    macropod, Jan 28, 2010
    #2
    1. Advertisements

  3. On Jan 28, 10:02 pm, "macropod" <> wrote:
    > Hi Steve,
    >
    > Try something along the lines of:
    > Sub UpdateRefTables()...


    Thanks macropod. That works a treat.

    Steve
     
    Steve Hodgson, Jan 29, 2010
    #3
  4. Steve Hodgson

    frank minor Guest

    Re: Hi Steve,Try something along the lines of:Sub UpdateRefTables()DimTOC As

    Hi macropad,

    I have utilized this VB script to attempt expanding the TOC in an automated batch fashion, but I am seeing something very strange appear, and that is a pop up box which states the following:

    Word is updating the table of contents. Select one of the following options:

    Update page numbers only
    Update entire table.

    I assumed using the TOC.update that the default would be the entire table would be updated. How can we get passed this and have the macro automatically make the TOC update properly. Please advise. Thanks in advance - frank

    > On Monday, January 25, 2010 1:37 PM Steve Hodgson wrote:


    > I have written a very simple VB Word macro to update the tables of
    > contents in a Word file but would like to extend this to include a
    > table of tables.
    >
    > The document includes a Table each of Contents, Figures and Tables
    > that I want to be able to updated without the need to hit <ctrl>-A, F9
    > and then make the selection to update all table contents three times.
    >
    > The macro below works for contents and figures but not for tables. Is
    > there a straightforward way to extend it to cover a table of tables
    > which is defined by { TOC /T "TAB_TITLE" \C }.
    >
    > Sub Update_TOC()
    > '
    > ' Update_TOC Macro
    > ' Macro created 20/01/2010
    > '
    > ActiveDocument.TablesOfContents(1).Update
    > ActiveDocument.TablesOfFigures(1).Update
    > End Sub



    >> On Thursday, January 28, 2010 5:02 PM macropod wrote:


    >> Hi Steve,
    >>
    >> Try something along the lines of:
    >> Sub UpdateRefTables()
    >> Dim TOC As TableOfContents ' Table of Contents Object
    >> Dim TOA As TableOfAuthorities ' Table of Authorities Object
    >> Dim TOF As TableOfFigures ' Table of Figures Object
    >> With ActiveDocument
    >> ' The following routines update TOC, TOA or TOF contents.
    >> ' Loop through Tables Of Contents and update
    >> For Each TOC In .TablesOfContents
    >> TOC.Update
    >> Next
    >> ' Loop through Tables Of Authorities and update
    >> For Each TOA In .TablesOfAuthorities
    >> TOA.Update
    >> Next
    >> ' Loop through Tables Of Figures and update
    >> For Each TOF In .TablesOfFigures
    >> TOF.Update
    >> Next
    >> End With
    >> End Sub
    >>
    >> --
    >> Cheers
    >> macropod
    >> [Microsoft MVP - Word]



    >>> On Friday, January 29, 2010 5:55 AM Steve Hodgson wrote:


    >>> Thanks macropod. That works a treat.
    >>>
    >>> Steve
     
    frank minor, Jun 9, 2011
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark, Luke and Corey

    TOC from highlighted text macro ???

    Mark, Luke and Corey, Sep 19, 2003, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    115
    Word Heretic
    Sep 19, 2003
  2. Rashun Mosley

    TOC Text and Header

    Rashun Mosley, Nov 11, 2003, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    137
    Cindy M -WordMVP-
    Nov 14, 2003
  3. Mikel

    TOC does not format correctly

    Mikel, Dec 23, 2003, in forum: Word VBA Beginners
    Replies:
    5
    Views:
    250
    Cindy M -WordMVP-
    Dec 30, 2003
  4. DebbiePartridge

    Checkign for TOC Fields in a document

    DebbiePartridge, Feb 20, 2004, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    123
    DebbiePartridge
    Feb 21, 2004
  5. sals

    creating TOC based on style, heading, title

    sals, Jun 21, 2004, in forum: Word VBA Beginners
    Replies:
    6
    Views:
    143
    JulieD
    Jun 29, 2004
  6. sals

    double spacing content of TOC

    sals, Jun 25, 2004, in forum: Word VBA Beginners
    Replies:
    2
    Views:
    206
  7. ML

    TOC Text Filtering...

    ML, Feb 15, 2005, in forum: Word VBA Beginners
    Replies:
    4
    Views:
    115
  8. Alterations to TOC

    , Mar 26, 2008, in forum: Word VBA Beginners
    Replies:
    1
    Views:
    108
    Tony Strazzeri
    Mar 28, 2008
Loading...