creating TOC based on style, heading, title

J

JulieD

Hi S

with reference to the specific question in the post (about including the
word "page") we dumped that idea but here's the code i used anyway in case
it can assist you in some way:

Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
With ActiveDocument.ActiveWindow.View 'ensure that show hide paragraph
marks are turned off
.ShowAll = False
.ShowParagraphs = False
End With
With ActiveDocument
.TablesOfContents.Add Range:=Selection.Range,
RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1,
LowerHeadingLevel:=1, _
IncludePageNumbers:=True, AddedStyles:="Heading 1,2,Title,1",
UseHyperlinks:=True, HidePageNumbersInWeb:= _
True, UseOutlineLevels:=False
.TablesOfContents(1).TabLeader = wdTabLeaderDots
.TablesOfContents.Format = wdIndexIndent
End With

'update toc
Call updatetoc


*******

the updatetoc just has the formatting setting for the TOC styles - i can
post this if you want
--

let me know if i can help further

Cheers
JulieD
 
S

sals

Hi Julie,

Your code works great! Thank you.
I'm trying to double space the table of contents and also insert the
text "Table of Contents" at the top centre of the document.
Any help will be great!

Thanks,

S
 
J

JulieD

Hi Sals

all i would personally do, is record changing the toc & putting table of
contents up the top & then cut & pasting the recorded bit at the end of the
previous bit of code :)

let us know how you go

Cheers
JulieD
 
S

sals

Julie,

I'm not sure how large the TOC will be, it's the selection the whole
TOC that I'm having trouble with. If I run a macro, it provides only
select however many lines and not the entire content. Is this the
approach you were describing? Or have i misinterpreted?

I'm trying to play around with ..
With ActiveDocument.TablesOfContents.Range.Paragraphs
.ParagraphFormat.LineSpacingRule = wdLineSpace1pt5
End With

and not having much luck...

Please advise

Thanks,

S
 
S

sals

ActiveDocument.TablesOfContents(1).Range.ParagraphFormat.LineSpacingRule
= wdLineSpace1pt5

this line of code does it!
 
J

JulieD

Hi sals

under insert / (references) / index & tables / table of contents you have
the abilityt to format the toc styles - this is what i would do, then it
doens't matter how long the table of contents actually is word will build it
with your style definition

but you've solved it anyway so that's great

Cheers
Julie
 

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