Macro help - Table of Contents

M

Mark Pitchford

Hi,

I'm new to this forum and just looking for a bit of help.

I currently have around 50 documents (the number will
increase dramatically in the future) with a Table of
Contents in each one created using the INSERT>Index and
Tables etc.

I need to copy the TOC from each document and paste it
into excel.

I currently have a macro which opens each document one by
one. The problem being I cant write the macro to find and
select the table of contents.

If anybody could help I would be very gratefull.

Regards,

Mark Pitchford.
 
P

Peter Hewett

Hi Mark Pitchford

Here's how to copy the first TOC of your document:

Public Sub CopyTOC()
With ActiveDocument.TablesOfContents
If .Count > 0 Then
.Item(1).Range.Copy
End If
End With
End Sub

HTH + Cheers - Peter
 
G

Guest

Hi Peter,

thank you very much, the macro works perfectly. I was
wondering, if I wanted to include the list of Tables and
List of figures, would I have to write three seperate
macros or is there a way to incorporate copying the
three "TOCs" in one go?

Many thanks again.

Regards,

Mark.
 
P

Peter Hewett

Hi <[email protected]>

The code is really copying a Range of text. This particular range happens to be TOC.
Other parts of you document are mapped by different objects and their range properties.

So the answer is no you can't do it in one go.

HTH + Cheers - Peter
 

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