TOC fills only 1/2 page

L

LEU

When I create a TOC it only fills a little over half a page and then goes to
the next page and does the same thing. How do I get it to fill the whole
page? I’m using Word 2003.
 
L

Lene Fredborg

I am not sure from your description, but the problem could be that one or
more of the TOC styles have been defined with “Page break before†turned on
(set in the Paragraph dialog box, Lines and Page Breaks tab). If this is the
case, modify the TOC style(s) in question.

Normally, TOC 1 is related to Heading 1, TOC 2 to Heading 2, etc.

For help on modifying a style, see:
http://www.shaunakelly.com/word/styles/ModifyAStyle.html

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
L

LEU

Hi Lene,

I am using TOC 1 and TOC 2. I do not see any Lines and Page breaks tab. Any
other ideas?
 
L

Lene Fredborg

The Line and Page Breaks tab is one of the tabs in the dialog box named
Paragraph.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
L

LEU

Lene,

Nothing is checked in the Line and Page Breaks. Also, if I create a TOC
using the toolbar it works (uses the full page). If I record it as a macro
and run it, it only uses half of the page.
 
L

Lene Fredborg

Could you post the macro? Maybe it will help finding the problem.
(I may not look at your macro until tomorrow - it is well after midnight in
Denmark now).

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
L

LEU

Lene,

Here it is.

Sub CreateTOC()

With ActiveDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 1").ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 1").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument.Styles("TOC 2")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 2").ParagraphFormat
.LeftIndent = InchesToPoints(0.5)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(-0.5)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 2").NoSpaceBetweenParagraphsOfSameStyle = True
With ActiveDocument.Styles("TOC 1")
.AutomaticallyUpdate = True
.BaseStyle = "Normal"
.NextParagraphStyle = "Normal"
End With
With ActiveDocument.Styles("TOC 1").ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0.5)
.SpaceBefore = 12
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
ActiveDocument.Styles("TOC 1").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=2, UseFields:=True, TableID:="C", _
IncludePageNumbers:=True, AddedStyles:="", UseHyperlinks:=False, _
HidePageNumbersInWeb:=True, UseOutlineLevels:=True
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With

End Sub
 
L

Lene Fredborg

I have looked at your code and tested it and I cannot see anything that
should cause the problems you experience.

Does the problem occur in a single document only?

Does it make any difference if you replace the code between “With
ActiveDocument†and “End With†by the following code?

Dim oField As Field
Set oField = .Fields.Add(Range:=Selection.Range, Type:=wdFieldEmpty)
With oField
.Code.Text = "TOC \o " & Chr(34) & "1-2" & Chr(34) & " \h \z "
.Update
End With
Set oField = Nothing

The code above adds a TOC field with the field code:
TOC \o “1-2†\h \z (delete \h from the code above if you do not want the
TOC entries to work as hyperlinks)
whereas the field inserted by your code has other switches:
TOC \o “1-2†\f \z \u

The Word help tells about the \u switch: Builds a table of contents by using
the applied paragraph outline level.

Do you have TC fields in the document? (the \f switch)

Actually, I cannot tell whether it would make any difference replacing the
code but it may be worth a try.

If it does not help, you could e-mail the problem document to me (you can
extract an e-mail address from my profile). I will then have a look in order
to see whether I can find out what happens.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
L

Lene Fredborg

When inserting the new code lines, you must keep the lines:
With ActiveDocument
(insert the code here)
End With

Maybe you removed the With/End With lines?

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
L

LEU

Lene,

The problem is in the \h . If I include it the macro the TOC fills the whole
page but the formatting is wrong. If I take out \h the TOC fills half the
page but the TOC format is correct.
 
L

LEU

Lene,

I figured out the problem. In the following part of the macro I deleted the
following line and it worked fine. The TOC filled the whole page.

HidePageNumbersInWeb:=True, UseOutlineLevels:=True


With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=2, UseFields:=True, TableID:="C", _
IncludePageNumbers:=True, AddedStyles:="", UseHyperlinks:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With
 
L

Lene Fredborg

I am definitely not sure what happens. Have you checked the style definition
of the Hyperlink style (applied as a character style on top of the TOC styles
when the \h switch is included)? By default, Hyperlink will be defined to add
blue color and underline - however, it may be modified to whatever a
character style can be.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top