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
Populating fields on creation of document (VSTO)
-
- 2StarLounger
- Posts: 107
- Joined: 23 Mar 2010, 13:42
-
- 5StarLounger
- Posts: 689
- Joined: 27 Jan 2010, 16:45
- Location: Ottawa, Ontario, Canada
Re: Populating fields on creation of document (VSTO)
Try:
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.TablesOfContents(1).Update
Regards
Don
Don
-
- 2StarLounger
- Posts: 107
- Joined: 23 Mar 2010, 13:42
Re: Populating fields on creation of document (VSTO)
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
Regards
Jack
-
- 5StarLounger
- Posts: 689
- Joined: 27 Jan 2010, 16:45
- Location: Ottawa, Ontario, Canada
Re: Populating fields on creation of document (VSTO)
Must be because I tested it while running 2003. There must be an equivalent in 2007.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
Regards
Don
Don
-
- 5StarLounger
- Posts: 689
- Joined: 27 Jan 2010, 16:45
- Location: Ottawa, Ontario, Canada
Re: Populating fields on creation of document (VSTO)
Hi JackJack21 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
You might want to take a look at this site.
Regards
Don
Don
-
- 2StarLounger
- Posts: 107
- Joined: 23 Mar 2010, 13:42
Re: Populating fields on creation of document (VSTO)
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
Regards
Jack
-
- 2StarLounger
- Posts: 107
- Joined: 23 Mar 2010, 13:42
Re: Populating fields on creation of document (VSTO)
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
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