Section TOC

K

Kerry Hewett

Hi

I am using Word XP.

I would like to automate my procedure of inserting a table
of contents relating to an individual section.

Currently I highlight the section, name it as a boomark,
insert a table of contents at the top of the section
(underneath the heading)and then modify the field code to
only look for data in the bookmark:-see below

{TOC \h \z \t "Section Sub Heading,2" \b SectionTwo}

Section Sub Heading is the name of my style I wish to be
listed in my Section TOC.

\b is the switch, followed by the name of the bookmark
SectionTwo

What I would like to be able to do is automate the whole
procedure. Here is my idea, I would really appreciate
some advice on whether you think this is a good way to go
about it and also some advice on a couple of commands I
have been unable to find information about.

I have the code for finding the number of sections in my
document, I will then loop through each section in the
document highlighting each section and naming it as a
boomark.

I would like the name of the bookmark to be the number of
the section (Section2,section7 etc..) How do I find out
the number of the section I have highlighted??

I can then insert an extra paragraph after the first
paragraph then insert a TOC.

How is best to automate the insertion of a TOC and then
add the switch \b followed by the name of the current
section bookmark.

I am really trying to decide whether automating this
procedure will be worthwhile. I would be grateful fo any
input. Thanks very much for your time.

Kerry.
 
D

Dave Lett

Hi Kerry,

I think you might find the following sample useful:

Dim iSec As Integer
Dim oRng As Range
Dim oRngStart As Range
For iSec = 1 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
.Fields.Add _
Range:=oRngStart, _
Type:=wdFieldTOC, _
Text:="Heading 1 \b Section" & iSec, _
PreserveFormatting:=True
End With
Next iSec

HTH,
Dave
 
K

Kerry Hewett

Works a treat - thanks very much.

Kez.
-----Original Message-----
Hi Kerry,

I think you might find the following sample useful:

Dim iSec As Integer
Dim oRng As Range
Dim oRngStart As Range
For iSec = 1 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
.Fields.Add _
Range:=oRngStart, _
Type:=wdFieldTOC, _
Text:="Heading 1 \b Section" & iSec, _
PreserveFormatting:=True
End With
Next iSec

HTH,
Dave




.
 

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