Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:02:22+00:00 2026-05-24T10:02:22+00:00

Does anyone know how when programmatically iterating through a word document, you can tell

  • 0

Does anyone know how when programmatically iterating through a word document, you can tell if a paragraph forms part of a table of contents (or indeed, anything else that forms part of a field).

My reason for asking is that I have a VB program that is supposed to extract the first couple of paragraphs of substantive text from a document – it’s doing so by iterating through the Word.Paragraphs collection. I don’t want the results to include tables of contents or other fields, I only want stuff that a human being would recognize as a header, title or a normal text paragraph. However it turns out that if there’s a table of contents, then not only the table of contents itself but EVERY line in the table of contents appears as a separate item in Word.Paragraphs. I don’t want these but haven’t been able to find any property on the Paragraph object that would allow me to distinguish and so ignore them (I’m guessing I need the solution to apply to other field types too, like table of figures and table of authorities, which I haven’t yet actually encountered but I guess potentially would cause the same problem)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:02:23+00:00Added an answer on May 24, 2026 at 10:02 am

    Because of the limitations in the Word object model I think the best way to achieve this would be to temporarily remove the TOC field code, iterate through the Word document, and then re-insert the TOC. In VBA, it would look like this:

    Dim doc As Document
    Dim fld As Field
    Dim rng As Range
    
    Set doc = ActiveDocument
    
    For Each fld In doc.Fields
        If fld.Type = wdFieldTOC Then
            fld.Select
            Selection.Collapse
            Set rng = Selection.Range 'capture place to re-insert TOC later
            fld.Cut
        End If
    Next
    

    Iterate through the code to extract paragraphs and then

    Selection.Range = rng
    Selection.Paste
    

    If you are coding in .NET this should translate pretty closely. Also, this should work for Word 2003 and earlier as is, but for Word 2007/2010 the TOC, depending on how it is created, sometimes has a Content Control-like region surrounding it that may require you to write additional detect and remove code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know if you can programmatically save a report shown in a reportviewer
Does anyone know if there any way that I can programmatically create a bean
Does anyone know how I can programmatically create a grid of squares. (each square
Does anyone know if you can programmatically open a .webarchive on the iPhone? A
Does anyone know a method to programmatically close the CD tray on Windows 2000
Does anyone know how to turn off iPhone's GPS programmatically? Once I use the
Does anyone know how I can programmaically move a registry from HKEY_LOCAL_MCAHINE to HKEY_CURRENT_USER?
Does anyone know how to programmatically determine the application IDs of the apps on
Does anyone know of a way to programmatically read the list of References in
Does anyone know if and how it is possible to search Google programmatically -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.