Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    TableOfContents (VBA/Word/2000)

    Hi All,

    I'm having trouble creating the following table of contents programmatically.

    { TOC o "1-4" f }

    This should create a Table of Contents using TC fields for levels 1 to 4.

    I don't seem to be able to do this through the Insert, Index and Tables command (therefore I can't record it!). And when I use the following code (and variations of it) it doesn't work:

    *********
    If Selection.StoryType <> wdMainTextStory Then
    ActiveDocument.ActiveWindow.View.SeekView = wdSeekMainDocument
    End If
    ActiveDocument.Bookmarks("StartOfDoc").Select
    Dim newTOC As TableOfContents
    Set newTOC = ActiveDocument.TablesOfContents.Add(Range:=Selecti on.Range)
    With newTOC
    .UseFields = True
    .UseHeadingStyles = False
    .UpperHeadingLevel = 1
    .LowerHeadingLevel = 4
    .RightAlignPageNumbers = True
    .IncludePageNumbers = True
    .Update
    End With
    newTOC.Range.Select
    ********
    This generates the following TOC field:

    { TOC f c }

    Is this a bug? Am I missing something?

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

    Re: TableOfContents (VBA/Word/2000)

    How about something simple like...

    <pre>Dim NewTOC as Field
    Set newTOC = ActiveDocument.Fields.Add(Range:=Selection.Range)
    newTOC.Code.Text = "TOC o ""1-4"" f"
    </pre>


    StuartR

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    Connecticut, USA
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: TableOfContents (VBA/Word/2000)

    Thanks Stuart,

    That is more or less what I ended up doing. However, when I went back to Word95 I noticed that the field code

    { TOC o "1-4" f }

    doesn't work there either! I mean it generates a TOC, but it doesn't restrict the output to levels 1 to 4. I had TC fields with level 5 on them and they were showing up to.

    Which leads to the next question... Is limiting the TOC levels not supported when using the f switch? I couldn't tell from the docs.

    Thanks again.

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

    Re: TableOfContents (VBA/Word/2000)

    Interesting. It behaves the same way for me, using Word 2000 SR1.

    It does what I expect with headings and no f field.

    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
  •