Populating fields on creation of document (VSTO)

Jack21
2StarLounger
Posts: 107
Joined: 23 Mar 2010, 13:42

Populating fields on creation of document (VSTO)

Post by Jack21 »

Hi - Can anyone help please?

I have a VSTO solution that creates a Report Template (which includes a Table of Contents). The user sees a taskpane and completes all the relevant information, which includes the removal of sections. The issue I have is that I need to repopulate the Table of Contents upon creation due to the removal of the section. I also need to repopulate the Title and Subtitle via a cross reference bookmark into the footer. Is there a way I can populate these fields programmatically? I am working in Word 2007.

Thanks
Jack

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Populating fields on creation of document (VSTO)

Post by Don Wells »

Try:
ActiveDocument.TablesOfContents(1).Update
Regards
Don

Jack21
2StarLounger
Posts: 107
Joined: 23 Mar 2010, 13:42

Re: Populating fields on creation of document (VSTO)

Post by Jack21 »

Thanks Don, have tried but alas does not work. I can select the table of contents and delete the table of contents but for some reason cannot update the table of contents.

Regards
Jack

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Populating fields on creation of document (VSTO)

Post by Don Wells »

Jack21 wrote:Thanks Don, have tried but alas does not work. I can select the table of contents and delete the table of contents but for some reason cannot update the table of contents.

Regards
Jack
Must be because I tested it while running 2003. There must be an equivalent in 2007.
Regards
Don

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Populating fields on creation of document (VSTO)

Post by Don Wells »

Jack21 wrote:Thanks Don, have tried but alas does not work. I can select the table of contents and delete the table of contents but for some reason cannot update the table of contents.

Regards
Jack
Hi Jack
    You might want to take a look at this site.
Regards
Don

Jack21
2StarLounger
Posts: 107
Joined: 23 Mar 2010, 13:42

Re: Populating fields on creation of document (VSTO)

Post by Jack21 »

Thanks Don. I've taken a look and it pretty much says exactly what you had already suggested. Previously, in Office 2003, I needed to change the page view, to Print Prview, to update the fields in a document. I am unsure whether this approach would work for Office 2007 but will take a look just in case.

Regards
Jack

Jack21
2StarLounger
Posts: 107
Joined: 23 Mar 2010, 13:42

Re: Populating fields on creation of document (VSTO)

Post by Jack21 »

I have come up with an alternative which is to use the TableofContents object:

docDocument.TablesOfContents.Add(Range:=docDocument.Bookmarks("bkmTOC").Range, _
UseFields:=False, UseHeadingStyles:=True, LowerHeadingLevel:=1, UpperHeadingLevel:=1)

This approach populates the TOC after the document has been created and appears to work as expected.

Regards
Jack