Inserting Table of Contents @ End of Word Document

M

Mark Holland

Hello,

I am using Word COM to automatically add some text to page 1 of a document,
then insert a TOC (Table of Contents) on Page 2.

I am struggling on how to tell it to insert the TOC at the END of the
document (As I am building it upwards). When I try and do an insert it
deletes the text I've placed on page 1.

set objword = CreateObject("Word.Application")
objword.visible = True
set objDoc = objword.Documents.Add()

set objSelection = objWord.Selection

objselection.TypeText("FIRST PAGE TEXT HERE")
objSelection.InsertBreak(7)

set myRange = objDoc.Range(0,0)
objdoc.TablesOfContents.Add myRange

Many Thanks in advance

Mark
 
L

Lene Fredborg

One way to solve the problem could be to replace your code line:
set myRange = objDoc.Range(0,0)
with
Set myRange = objdoc.Range.Characters.Last

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

fumei via OfficeKB.com

When I try and do an insert it
deletes the text I've placed on page 1.

set myRange = objDoc.Range(0,0)
This sets the range for page 1!

so THIS puts theToC on Page 1, not 2
 

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