+ Reply to Thread
Results 1 to 9 of 9

Creating Table of Content ( not heading / subheading )

  1. #1
    Registered User
    Join Date
    02-18-2011
    Location
    MY
    MS-Off Ver
    Excel 2003
    Posts
    19

    Creating Table of Content ( not heading / subheading )

    Hi Gurus,

    Using Microsoft Word - VBA, is it possible to create a VBA macro to read from a table and then create a table of content ?

    I have tried macro to create Table of Content based on Heading and Subheading and no issue with that. However, I can't get the right when I loop through the table.

    Example in my Table

    Row 1 - Cell_1, Cell_2, Cell_3
    Row 2 - Cell_1, Cell_2, Cell_3
    Row 3 - Cell_1, Cell_2, Cell_3

    I would like to take the text from Cell_2 and create a table of content.

    Row_1-Cell_2 ... page 1
    Row_2-Cell_2 ... page 3
    Row_3-Cell_2 ... page 3

    Can I utilize the Add Method as decribed here ? http://msdn.microsoft.com/en-us/libr.../ff835785.aspx

    Any example that you can share ? Thanks.

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Creating Table of Content ( not heading / subheading )

    Why would a macro try to read from a table to build a Table of Contents? As I said in your other thread, all you need do is (a) use heading Styles for whatever you want the Table of Contents to contain, then (b) insert a TOC field (e.g. as per the MSDN link) where you want the Table of Contents to appear.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    02-18-2011
    Location
    MY
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Creating Table of Content ( not heading / subheading )

    Quote Originally Posted by macropod View Post
    Why would a macro try to read from a table to build a Table of Contents? As I said in your other thread, all you need do is (a) use heading Styles for whatever you want the Table of Contents to contain, then (b) insert a TOC field (e.g. as per the MSDN link) where you want the Table of Contents to appear.
    Well, that's the requirement from my user. In the Word document, there are heading 1 and heading 2 which will form the TOC in the first few pages of the document.

    Then, there's a table in the middle part of the document that contains some information which the user want it to be indexed in another TOC at the end of the document.

    The heading styles you mean is only heading 1 and heading 2 ? or I can create a new heading style myself and ask TOC to generate it for me ?

    I found a solution by creating a bookmark in each table cell. However, it is still not a very good way. I would prefer to loop through the table cell and add it manually. However, not able to get the code correct. Sigh ...

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Creating Table of Content ( not heading / subheading )

    Quote Originally Posted by davidku View Post
    In the Word document, there are heading 1 and heading 2 which will form the TOC in the first few pages of the document.

    Then, there's a table in the middle part of the document that contains some information which the user want it to be indexed in another TOC at the end of the document.

    The heading styles you mean is only heading 1 and heading 2 ? or I can create a new heading style myself and ask TOC to generate it for me ?
    In that case, you would do better to use a different set of Heading Styles for the table, then create a second Table of Contents that references only those heading levels (making sure also to specify the required heading levels for the first Table of Contents. No need to bookmark anything or to process the table in any particular way.

  5. #5
    Registered User
    Join Date
    02-18-2011
    Location
    MY
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Creating Table of Content ( not heading / subheading )

    Quote Originally Posted by macropod View Post
    In that case, you would do better to use a different set of Heading Styles for the table, then create a second Table of Contents that references only those heading levels (making sure also to specify the required heading levels for the first Table of Contents. No need to bookmark anything or to process the table in any particular way.
    Actually, I found a simpler solution.
    Loop through the table cell, and use Add Bookmark.
    Then, go to end of the document and create TOC using Bookmark. Viola !
    No need to mess up the heading styles.

    Just got to figure out what function to use in the code.
    Not too familiar with Word, it is much easier to do it in Excel.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Creating Table of Content ( not heading / subheading )

    That is by no means simpler, and it is far more prone to corruption ...

  7. #7
    Registered User
    Join Date
    02-18-2011
    Location
    MY
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Creating Table of Content ( not heading / subheading )

    Quote Originally Posted by macropod View Post
    That is by no means simpler, and it is far more prone to corruption ...
    So, it is not a good approach ? I thought I found a gem but it seems, not the ideal case.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Creating Table of Content ( not heading / subheading )

    As a rule, you'd only use bookmarks with a TOC field if you're wanting to restrict the TOC content to headings in the bookmarked range. Bookmarking cell content & referencing bookmarks in table cells can lead to anomalies such as the reference replicating the entire cell (not just its contents). Coupled with the fact bookmarks are:
    • easily deleted by accident;
    • require careful editing to ensure intended additions fall within their range; and
    • are prone to being extended by accident to include unintended content,
    they're not a good choice for what you have in mind.

  9. #9
    Registered User
    Join Date
    02-18-2011
    Location
    MY
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Creating Table of Content ( not heading / subheading )

    Thanks for your input. Sorry, this is the first time I create Word VBA so kind of new. All the while I am working on Excel VBA and realized that they are 2 different thing.

    I'll just create a new style - TOCtable and create another TOC at the end of the article using the this style instead.
    The coding also much simpler.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find heading, the subheading, display value
    By mprpich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-17-2014, 09:58 AM
  2. Replies: 4
    Last Post: 07-22-2010, 04:17 PM
  3. Delete & Move columns based on Heading content
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2007, 10:09 AM
  4. [SOLVED] In a table produce an value by column heading and row heading
    By naflan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-27-2005, 01:25 PM
  5. Creating a Table of Content in Excel
    By Michiel Junge in forum Excel General
    Replies: 1
    Last Post: 02-14-2005, 09:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1