Forms and Getting Macros to work

G

Guest

Hello,

I attached macros to a form so that fields can be updated automatically in
the Table of Contents and Footer sections of a document.

When the form was built in XP everything worked fine. Then, when I used it
in Windows 2000, the macros and assigned macro keys did not work. I tweaked
the form for Windows 2000 and it half worked - the Footer Fields would
automatically re-populate but the TOC wouldn't refresh. Then, I tested the
form on a colleague's machine (she also had Windows 2000) and the macro keys
didn't work at all although she could manually run the macro - the Footer
fields did refresh, but, again, no luck with the TOC.

Please can someone advise on how to get a TOC to refresh via a macro. I want
the form to remain protected as much as possible. I tried

activedocument.updatetableofcontentsfull

but nothing happend.

Also, why would we have different experiences if we're both using Windows
2000?

Any pointers would be appreciated. Valerie Ng.
 
G

Graham Mayor

In order to get REF fields in a header/footer to update automatically from a
form field, you need to force an update with a macro run on exit from the
form field. (Styleref fields don't need such encouragement - they will
reflect the content of the styles, though checking the calculate on exit
check box of the relevant field would help). There is a variety of macro
code around to effect updates eg -

Sub Update()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim oTOC As TableOfContents
For Each oTOC In ActiveDocument.TablesOfContents
oTOC.Update
Next oTOC
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
oField.Update
Next oField
End If
Next oFooter
Next oSection
End Sub

but I tend to use the all encompassing code listed on my web site at
http://www.gmayor.com/installing_macro.htm

Save the form as a template and set Word's macro security to trust all
installed templates and add-ins.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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