I have a script agent that runs on selected documents that takes the Word file attachments from those documents and merges them into one new Word file (thanks to stamp). The script begins like this:
==== BEGIN CODE ====
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim word As Variant
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set word = CreateObject("Word.application")
word.Application.Visible = True
word.Application.Selection.TypeText("Document merged from Notes Database ")
===== END CODE =====
From there, it cycles through the unprocessed documents, merging the attachments. (There are other objects declared for those, edited here for simplicity.)
What I would like to do is insert a table of contents at the beginning of the file.
I've tried adding this just before the word.Application.Selection.InsertBreak 2
==== BEGIN CODE ====
word.Application.Selection.TablesOfContents.Add word.Application.Selection.Range, True, 1, 2, False, 1, True, True
===== END CODE ====
The parameter list for the TablesOfContents.Add method (listed under the heading of the Microsoft Word 9.0 Object Library in the list of OLE Classes) is:
Add(range, optional useheadingstyles as variant, optional upperheadinglevel as variant, optional lowerheadinglevel as variant, optional usefields as variant, optional tableid as variant, optional rightalignpagenumbers as variant, optional includepagenumbers as variant, optional addedstyles as variant, optional usehyperlinks as variant, optional hidepagenumbersinweb as variant) as variant
When I run this, I get a pop-up error: "Instance member TABLESOFCONTENTS does not exist" and the script stops running.
I've tried it with word.Application.Selection.TablesOfContents.Add, with word.Application.TablesOfContents.Add, and with word.TablesOfContents.Add, each time getting the same error.
I imagine there's some quirky little thing that I'm just missing, as this is my first poke through the OLE Classes list, and I'm not real sure what I'm doing. Can someone point me in the right direction?