Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Aug 2006
    Posts
    784
    Thanks
    0
    Thanked 0 Times in 0 Posts

    TOC borders (2003)

    Dear Loungers,

    I am using a TOC in Word, and the right tab for my TOC 2 style is set for 6.5 inches, because that is the where the right border of most of my documents using that tab is located. However, I find a degree in inconvenience in this setting, because I sometimes change the page margins in the border, and since the TOC right tab and right indentation are not set to automatically right align with the right border, I always have to go into there and manually change the settings (and untick "Automatically update document styles"). This becomes problematic when in a single document, different sections have different right borders (with some of the having TOC going too far deep and others not deep enough).

    Is there a way to tell Word to automatically detect where the right margin of a page is and to set the right tab and right border of TOC 2 (and all the TOC styles for that matter) accordingly?

    Thanks!

    JMT

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: TOC borders (2003)

    No, not as far as I know.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: TOC borders (2003)

    As I wrote, I don't know of a way to make Word do this automatically. However, you may be able to adapt the following macro to do what you want. You'd have to run it when the document is (more or less) finished, and run it again if you change the margins of a section.

    Sub FixTOCs()
    Dim i As Integer
    Dim toc As TableOfContents
    Dim par As Paragraph
    Dim dblPos As Double

    ' Make sure that "Automatically update" is off
    For i = 1 To 9
    ActiveDocument.Styles("TOC " & i).AutomaticallyUpdate = False
    Next i

    ' Loop through the TOCs
    For Each toc In ActiveDocument.TablesOfContents
    ' Compute the position for the tab stop.
    With toc.Range.Sections(1).PageSetup
    dblPos = .PageWidth - .LeftMargin - .RightMargin
    End With
    ' Loop through the paragraphs in the TOC
    For Each par In toc.Range.Paragraphs
    If Left(par.Style, 3) = "TOC" Then
    ' If it has a TOC style, clear existing tabs...
    par.TabStops.ClearAll
    ' ... and add a new one at the computed position
    par.TabStops.Add dblPos, wdAlignTabRight, wdTabLeaderDots
    End If
    Next par
    Next toc
    End Sub

Posting Permissions

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