table of contents

E

Evens

How can you regenerate a complete table of content using code?

I have a form in the first page of my document and I dont want the entire
doc to be updated. In the second page, I have a table of contents and I want
to create a button who will regenerate the table with all the new points add
in the document.

I've try something like that:

Me.Protect (wdNoProtection)
Selection.WholeStory
Selection.Fields.UpdateSource
Me.Protect (wdAllowOnlyFormFields)

but first, the first line doesnt work because of the current protection and
doesnt want to remove it. And second point, I select the whole document and I
just want to select all but the first page.

Can you help me please!!!!
Thanks
 
D

Dave Lett

Hi,

I think you can use the following if you want to update the contents of an
existing TOC.

ActiveDocument.TablesOfContents(1).Update

HTH,
Dave
 
T

Tony Jollans

1. Use Document.UNProtect to unprotect a document.

2. Try using Document.TablesOfContents(1).Update to just update a TOC,
 
E

Evens

thanks for your help, my second problem is now fix but for my first problem:

it doesnt work, possibly because of the forms protection activate when I
launch the code.

How to deactivate the protection before executing this command? I know how
to reactivate the protection but not how to shut it off.

Me.Protect (wdNoProtection) ' this line doesnt work!!!!
ActiveDocument.TablesOfContents(1).Update
Me.Protect (wdAllowOnlyFormFields)
 
J

Jean-Guy Marcil

Evens was telling us:
Evens nous racontait que :
thanks for your help, my second problem is now fix but for my first
problem:

it doesnt work, possibly because of the forms protection activate
when I launch the code.

How to deactivate the protection before executing this command? I
know how to reactivate the protection but not how to shut it off.

Me.Protect (wdNoProtection) ' this line doesnt work!!!!
ActiveDocument.TablesOfContents(1).Update
Me.Protect (wdAllowOnlyFormFields)

Why are you using the "Me" keyword *and* ActiveDocument to refer to the same
object?

ActiveDocument.Unprotect "myPasword"

will do the job. Note that "myPasword" is optional, depending on the
presence or not of a password.


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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