Update table of contents in a protected for forms document

G

Guest

In Word 2003 I have created a template with form fields and styles. The
parts of the documents with fields are protected, the rest of the document
including the table of contents is not.

My problem is that I need the table of contents to update either when the
document is printed or with the F9 key or with the right mouse click update
fields and this will only happen if the whole document is unprotected. For
the sanity of the marketing team I cannot leave the document unprotected.

HELP!
 
J

Jay Freedman

The only reasonable way to achieve this is with a macro that unprotects the
document, updates the table of contents, and reprotects the document. This
should do:

Sub UpdateProtectedTOC()
Dim TOC As TableOfContents

With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If

For Each TOC In .TablesOfContents
TOC.Update
Next

.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End With
End Sub

You'll need to put this macro in the template, along with a keyboard
shortcut or toolbar button to run it. The template will have to be made
available to everyone who has to create or edit these documents -- if they
get the document without the template, the macro won't be available.

To make the macro run whenever the document is printed, you need two more
macros:

Sub FilePrint()
UpdateProtectedTOC
Dialogs(wdDialogFilePrint).Show
End Sub

Sub FilePrintDefault()
UpdateProtectedTOC
ActiveDocument.PrintOut Background:=False
End Sub

Read these articles to find out what to do with the macros.
http://www.gmayor.com/installing_macro.htm
http://www.gmayor.com/Template_Locations.htm
http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
G

Guest

Thank you Jay, that works a treat. I guess that I will have to learn VBA now.

Regards
JaneH
 

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