K
Kerry
Hi,
I have a procedure (see below) which inserts a table of
contents relative to the section. This procedure works
wonderfully however the placement of the section contents
table is not correct, I would like the table to be
inserted under the heading not at the top of the section.
I do not know how to change my code.
Any advice would be greatly appreciated. Thanks very much
for your time.
Kerry
Sub SecTOC()
'Insert a table of contents for each section
'Highlights all text within a section, naming it as a
bookmark
'Inserts a table of contents showing only section sub
heading (level 2) styles
'Add switch to the table of contents field to only
look in bookmark
Dim iSec As Integer
Dim oRng As Range
Dim oRngStart As Range
For iSec = 2 To ActiveDocument.Sections.Count
With ActiveDocument
Set oRng = .Sections(iSec).Range
Set oRngStart = .Range _
(Start:=.Sections(iSec).Range.Start, _
End:=.Sections(iSec).Range.Start)
.Bookmarks.Add _
Name:="Section" & iSec, _
Range:=oRng
Secbk = "toc \h \z \t ""section sub heading,2""
\b ""section" & iSec
.Fields.Add oRngStart, Type:=wdFieldEmpty,
Text:=Secbk & """, PreserveFormatting:=False"
Selection.Fields.Update
End With
Next iSec
End Sub
I have a procedure (see below) which inserts a table of
contents relative to the section. This procedure works
wonderfully however the placement of the section contents
table is not correct, I would like the table to be
inserted under the heading not at the top of the section.
I do not know how to change my code.
Any advice would be greatly appreciated. Thanks very much
for your time.
Kerry
Sub SecTOC()
'Insert a table of contents for each section
'Highlights all text within a section, naming it as a
bookmark
'Inserts a table of contents showing only section sub
heading (level 2) styles
'Add switch to the table of contents field to only
look in bookmark
Dim iSec As Integer
Dim oRng As Range
Dim oRngStart As Range
For iSec = 2 To ActiveDocument.Sections.Count
With ActiveDocument
Set oRng = .Sections(iSec).Range
Set oRngStart = .Range _
(Start:=.Sections(iSec).Range.Start, _
End:=.Sections(iSec).Range.Start)
.Bookmarks.Add _
Name:="Section" & iSec, _
Range:=oRng
Secbk = "toc \h \z \t ""section sub heading,2""
\b ""section" & iSec
.Fields.Add oRngStart, Type:=wdFieldEmpty,
Text:=Secbk & """, PreserveFormatting:=False"
Selection.Fields.Update
End With
Next iSec
End Sub