Reply
 
Thread Tools Display Modes
  #1   Report Post  
linda
 
Posts: n/a
Default macro for updating TOC page numbers

I have a protected form, and I know that page numbers for the TOC sometimes
do not get updated correctly with protected forms. Does anyone have a
sample macro that would work for this? I am not good with macros, so any
helo would be apppreciated.

Thanks,

Linda.


  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

linda wrote:
I have a protected form, and I know that page numbers for the TOC
sometimes do not get updated correctly with protected forms. Does
anyone have a sample macro that would work for this? I am not good
with macros, so any helo would be apppreciated.

Thanks,

Linda.


Hi Linda,

The macro needs to unprotect the document, do the update, and reprotect the
document. Here's sample code:

Public Sub UpdateTOC()
Dim oTOC As TableOfContents
Dim oldProt As WdProtectionType

'IMPORTANT: If the document protection
'includes a password, add the password
'as a parameter to the .Unprotect and
'.Protect calls.

'save the existing protection type
oldProt = ActiveDocument.ProtectionType
If oldProt wdNoProtection Then
ActiveDocument.Unprotect ' Password:="password"
End If

For Each oTOC In ActiveDocument.TablesOfContents
oTOC.Update
Next oTOC

'restore the old protection
If oldProt wdNoProtection Then
ActiveDocument.Protect Type:=oldProt, _
NoReset:=True
' , Password:="password"
End If
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
TOC page numbers not updating on locked documents linda Microsoft Word Help 1 December 11th 04 10:48 PM
I am having trouble with page numbers and the table of contents m. page numbers and toc Microsoft Word Help 1 December 10th 04 01:31 PM
Word 2003 printing {PAGE} instead of page numbers Jayz Microsoft Word Help 2 December 7th 04 08:25 AM
Problem with Page Numbers in Index using Word 2002 jdkelley Microsoft Word Help 1 December 1st 04 03:32 PM
Wrong Page Numbers in Table of Contents latteluvva Microsoft Word Help 1 November 26th 04 07:01 AM


All times are GMT +1. The time now is 11:39 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"