Reply
 
Thread Tools Display Modes
  #1   Report Post  
La La Lara
 
Posts: n/a
Default Macro to update ToC in a form - I'm stuck!

Hi guys

I am a bit stuck. I have a form which has a ToC in it. I have used the
code at
http://word.mvps.org/FAQs/MacrosVBA/...lfResetOff.htm.
which works fine to uprotect the doc, then I can manually left-click by the
ToC, hit F9 and it updates, then the macro will reprotect the form without
losing any of the info in the form fields. It works a treat.

BUT....! It would be even more seamless to the user if I could add a bit of
VB code that will unlock the form, *automatically update the fields*, then
reprotect the form without losing any of the form field info (so that the
user can simply click an icon on the toolbar which will do all this instead
if him/her having to go to the ToC and cliking F9)

I did try to cobble together some code but it wouldn't work.

Can anyone help?
  #2   Report Post  
Charles Kenyon
 
Posts: n/a
Default

I haven't tested the following with a TOC field but it should work.

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub

Try putting this in your module and calling it from your unprotect /
reprotect procedure or simply add the code to your procedure. Hope this
helps.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Hi guys

I am a bit stuck. I have a form which has a ToC in it. I have used the
code at
http://word.mvps.org/FAQs/MacrosVBA/...lfResetOff.htm.
which works fine to uprotect the doc, then I can manually left-click by
the
ToC, hit F9 and it updates, then the macro will reprotect the form without
losing any of the info in the form fields. It works a treat.

BUT....! It would be even more seamless to the user if I could add a bit
of
VB code that will unlock the form, *automatically update the fields*, then
reprotect the form without losing any of the form field info (so that the
user can simply click an icon on the toolbar which will do all this
instead
if him/her having to go to the ToC and cliking F9)

I did try to cobble together some code but it wouldn't work.

Can anyone help?



  #3   Report Post  
La La Lara
 
Posts: n/a
Default

Thanks Charles.

I have now got the following in the "Microsoft Word Objects" part of the VB
window, under "This document":

Sub ToolsProtectUnprotectDocument()

Dim oDoc As Document
Set oDoc = ActiveDocument

On Error GoTo ErrMess
If oDoc.ProtectionType = wdNoProtection Then
With Dialogs(wdDialogToolsProtectDocument)
.noreset = True
.Show
End With
Else
oDoc.Unprotect
End If
Exit Sub

ErrMess:
MsgBox Err.Description, vbInformation

End Sub

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub



Sub ProtectForm()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If
End Sub


But it doesn't work, as when I run the macro it only runs the first
"section" of it, i.e.
ToolsProtectUnprotectDocument.

I really don't know much about VB code, so I am confused as to how to get
the macro to go though all the 3 sections of the code above. Am I making any
sense???!!!




"Charles Kenyon" wrote:

I haven't tested the following with a TOC field but it should work.

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub

Try putting this in your module and calling it from your unprotect /
reprotect procedure or simply add the code to your procedure. Hope this
helps.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Hi guys

I am a bit stuck. I have a form which has a ToC in it. I have used the
code at
http://word.mvps.org/FAQs/MacrosVBA/...lfResetOff.htm.
which works fine to uprotect the doc, then I can manually left-click by
the
ToC, hit F9 and it updates, then the macro will reprotect the form without
losing any of the info in the form fields. It works a treat.

BUT....! It would be even more seamless to the user if I could add a bit
of
VB code that will unlock the form, *automatically update the fields*, then
reprotect the form without losing any of the form field info (so that the
user can simply click an icon on the toolbar which will do all this
instead
if him/her having to go to the ToC and cliking F9)

I did try to cobble together some code but it wouldn't work.

Can anyone help?




  #4   Report Post  
Charles Kenyon
 
Posts: n/a
Default

Try

Sub TOCUpdateMaster()
ToolsProtectUnprotectDocument
TOCFieldUpdate
ProtectForm
End Sub

--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Thanks Charles.

I have now got the following in the "Microsoft Word Objects" part of the
VB
window, under "This document":

Sub ToolsProtectUnprotectDocument()

Dim oDoc As Document
Set oDoc = ActiveDocument

On Error GoTo ErrMess
If oDoc.ProtectionType = wdNoProtection Then
With Dialogs(wdDialogToolsProtectDocument)
.noreset = True
.Show
End With
Else
oDoc.Unprotect
End If
Exit Sub

ErrMess:
MsgBox Err.Description, vbInformation

End Sub

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub



Sub ProtectForm()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If
End Sub


But it doesn't work, as when I run the macro it only runs the first
"section" of it, i.e.
ToolsProtectUnprotectDocument.

I really don't know much about VB code, so I am confused as to how to get
the macro to go though all the 3 sections of the code above. Am I making
any
sense???!!!




"Charles Kenyon" wrote:

I haven't tested the following with a TOC field but it should work.

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub

Try putting this in your module and calling it from your unprotect /
reprotect procedure or simply add the code to your procedure. Hope this
helps.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Hi guys

I am a bit stuck. I have a form which has a ToC in it. I have used
the
code at
http://word.mvps.org/FAQs/MacrosVBA/...lfResetOff.htm.
which works fine to uprotect the doc, then I can manually left-click by
the
ToC, hit F9 and it updates, then the macro will reprotect the form
without
losing any of the info in the form fields. It works a treat.

BUT....! It would be even more seamless to the user if I could add a
bit
of
VB code that will unlock the form, *automatically update the fields*,
then
reprotect the form without losing any of the form field info (so that
the
user can simply click an icon on the toolbar which will do all this
instead
if him/her having to go to the ToC and cliking F9)

I did try to cobble together some code but it wouldn't work.

Can anyone help?






  #5   Report Post  
La La Lara
 
Posts: n/a
Default

THANK YOU so much!!!!

"Charles Kenyon" wrote:

Try

Sub TOCUpdateMaster()
ToolsProtectUnprotectDocument
TOCFieldUpdate
ProtectForm
End Sub

--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Thanks Charles.

I have now got the following in the "Microsoft Word Objects" part of the
VB
window, under "This document":

Sub ToolsProtectUnprotectDocument()

Dim oDoc As Document
Set oDoc = ActiveDocument

On Error GoTo ErrMess
If oDoc.ProtectionType = wdNoProtection Then
With Dialogs(wdDialogToolsProtectDocument)
.noreset = True
.Show
End With
Else
oDoc.Unprotect
End If
Exit Sub

ErrMess:
MsgBox Err.Description, vbInformation

End Sub

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub



Sub ProtectForm()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If
End Sub


But it doesn't work, as when I run the macro it only runs the first
"section" of it, i.e.
ToolsProtectUnprotectDocument.

I really don't know much about VB code, so I am confused as to how to get
the macro to go though all the 3 sections of the code above. Am I making
any
sense???!!!




"Charles Kenyon" wrote:

I haven't tested the following with a TOC field but it should work.

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub

Try putting this in your module and calling it from your unprotect /
reprotect procedure or simply add the code to your procedure. Hope this
helps.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Hi guys

I am a bit stuck. I have a form which has a ToC in it. I have used
the
code at
http://word.mvps.org/FAQs/MacrosVBA/...lfResetOff.htm.
which works fine to uprotect the doc, then I can manually left-click by
the
ToC, hit F9 and it updates, then the macro will reprotect the form
without
losing any of the info in the form fields. It works a treat.

BUT....! It would be even more seamless to the user if I could add a
bit
of
VB code that will unlock the form, *automatically update the fields*,
then
reprotect the form without losing any of the form field info (so that
the
user can simply click an icon on the toolbar which will do all this
instead
if him/her having to go to the ToC and cliking F9)

I did try to cobble together some code but it wouldn't work.

Can anyone help?








  #6   Report Post  
Charles Kenyon
 
Posts: n/a
Default

You are welcome.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
THANK YOU so much!!!!

"Charles Kenyon" wrote:

Try

Sub TOCUpdateMaster()
ToolsProtectUnprotectDocument
TOCFieldUpdate
ProtectForm
End Sub

--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Thanks Charles.

I have now got the following in the "Microsoft Word Objects" part of
the
VB
window, under "This document":

Sub ToolsProtectUnprotectDocument()

Dim oDoc As Document
Set oDoc = ActiveDocument

On Error GoTo ErrMess
If oDoc.ProtectionType = wdNoProtection Then
With Dialogs(wdDialogToolsProtectDocument)
.noreset = True
.Show
End With
Else
oDoc.Unprotect
End If
Exit Sub

ErrMess:
MsgBox Err.Description, vbInformation

End Sub

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub



Sub ProtectForm()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
noreset:=True
End If
End Sub


But it doesn't work, as when I run the macro it only runs the first
"section" of it, i.e.
ToolsProtectUnprotectDocument.

I really don't know much about VB code, so I am confused as to how to
get
the macro to go though all the 3 sections of the code above. Am I
making
any
sense???!!!




"Charles Kenyon" wrote:

I haven't tested the following with a TOC field but it should work.

Sub TOCFieldUpdate()
' Written by Charles Kyle Kenyon 27 January 2005
' Field Updater - TOC fields
Dim oField As Field
On Error Resume Next
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldTOC Then
oField.Update
End If
Next oField
End Sub

Try putting this in your module and calling it from your unprotect /
reprotect procedure or simply add the code to your procedure. Hope
this
helps.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"La La Lara" wrote in message
...
Hi guys

I am a bit stuck. I have a form which has a ToC in it. I have used
the
code at
http://word.mvps.org/FAQs/MacrosVBA/...lfResetOff.htm.
which works fine to uprotect the doc, then I can manually left-click
by
the
ToC, hit F9 and it updates, then the macro will reprotect the form
without
losing any of the info in the form fields. It works a treat.

BUT....! It would be even more seamless to the user if I could add a
bit
of
VB code that will unlock the form, *automatically update the
fields*,
then
reprotect the form without losing any of the form field info (so
that
the
user can simply click an icon on the toolbar which will do all this
instead
if him/her having to go to the ToC and cliking F9)

I did try to cobble together some code but it wouldn't work.

Can anyone help?








  #7   Report Post  
 
Posts: n/a
Default

Charles, any way to get this to update the entire table and not just
page numbers only?
Thanks.

  #8   Report Post  
Charles Kenyon
 
Posts: n/a
Default

I didn't know that it only did the page numbers. I would suggest creating a
document with a TOC. Make some changes that would add lines.

Record two macros, one updating the TOC with only page numbers being
updated. The second with the entire table being updated. Then look at the
code produced and see if you can discern a difference. That is what I would
do, but since it is your problem, I'll leave it for you to do. Please report
back the results.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

wrote in message
oups.com...
Charles, any way to get this to update the entire table and not just
page numbers only?
Thanks.



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
Add a new page in a form by using a macro??? La La Lara Microsoft Word Help 1 January 19th 05 05:41 PM
Auto Updating TOC in Protected Form Scott Cooper Microsoft Word Help 2 January 9th 05 02:32 AM
macro for unprotecting form, update TOC, then reprotect form?? linda Microsoft Word Help 1 December 15th 04 02:31 PM
Text Form Field Ref in Footer Won't Update on Screen StarWine Microsoft Word Help 3 December 6th 04 06:17 PM
2000 to 2002 macro and "Could not open macro storage" Art Farrell Mailmerge 1 December 6th 04 12:40 PM


All times are GMT +1. The time now is 02:00 AM.

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"