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

Re: table of contents by Dave

Dave
Mon Apr 24 13:25:48 CDT 2006

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


"Evens" <Evens@discussions.microsoft.com> wrote in message
news:55F8437B-A398-4C8E-9382-99DD579B6A64@microsoft.com...
> 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



Re: table of contents by Tony

Tony
Mon Apr 24 13:30:17 CDT 2006

1. Use Document.UNProtect to unprotect a document.

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

--
Enjoy,
Tony

"Evens" <Evens@discussions.microsoft.com> wrote in message
news:55F8437B-A398-4C8E-9382-99DD579B6A64@microsoft.com...
> 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



Re: table of contents by Evens

Evens
Mon Apr 24 13:42:02 CDT 2006

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)

"Dave Lett" wrote:

> 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
>
>
> "Evens" <Evens@discussions.microsoft.com> wrote in message
> news:55F8437B-A398-4C8E-9382-99DD579B6A64@microsoft.com...
> > 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
>
>
>

Re: table of contents by Evens

Evens
Mon Apr 24 13:46:03 CDT 2006

Excellent,

With the
activevedocument.unprotect

its work
thanks for help

"Tony Jollans" wrote:

> 1. Use Document.UNProtect to unprotect a document.
>
> 2. Try using Document.TablesOfContents(1).Update to just update a TOC,
>
> --
> Enjoy,
> Tony
>
> "Evens" <Evens@discussions.microsoft.com> wrote in message
> news:55F8437B-A398-4C8E-9382-99DD579B6A64@microsoft.com...
> > 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
>
>
>

Re: table of contents by Jean-Guy

Jean-Guy
Mon Apr 24 15:34:51 CDT 2006

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
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org