[mso] Re: Repeating Fields Word Forms

  • From: "Chinell, David F (GE EntSol, Security)" <David.Chinell@xxxxxx>
  • To: <mso@xxxxxxxxxxxxx>
  • Date: Wed, 21 Oct 2009 12:46:04 -0400

Michele:

Three ideas.

1. A really simply trick is to have your users click Tools > Options >
Print, and then check the Update Fields check box. This tells Word to
update all fields before displaying the Print Preview. Then you tell the
users to just "toggle into and out of" Print Preview to update all the
fields. This has the advantage that it updates fields in the headers and
footers as well, which Ctrl + A, F9 doesn't.

2. The problem with code to update all the fields is finding and
trapping an event to trigger the code. I never implemented a fully
automatic method of doing this, as I always want to retain control over
when fields do or don't get updated.

3. Compensating for the shortcomings of Ctrl + A, F9 (updating fields in
the headers and footers, and in text boxes) turns out to be a bigger
problem than one might think. But I settled on a medium-sized chunk of
VBA that gets most of the situations we use here. I added a command Edit
> Update All Fields and assigned it the keyboard shortcut Ctrl + Alt +
F9 and added a toolbar button in the Cut - Copy - Paste area of a
standard toolbar. That way the users can update all the fields whenever
they want. The code:

~~~~~

Sub UpdateAllFields()

' Updates all fields in the document body,
' headers, and footers.

Dim objSection As Section
Dim objHeaderFooter As HeaderFooter

Dim strErrorText As String

Setup:

On Error GoTo Error
'MsgBox "On Error!"
System.Cursor = wdCursorWait
Application.ScreenUpdating = False

Main:

ActiveDocument.Fields.Update

For Each objSection In ActiveDocument.Sections
    For Each objHeaderFooter In objSection.Headers
        objHeaderFooter.Range.Fields.Update
    Next objHeaderFooter
    For Each objHeaderFooter In objSection.Footers
        objHeaderFooter.Range.Fields.Update
    Next objHeaderFooter
Next objSection

GoTo Done

Error:

Select Case Err.Number
    Case 4248
        strErrorText = _
            "Position the insertion point in an open document" &
vbNewLine & _
            "before updating the fields."
    Case Else
        strErrorText = _
            "Unexpected error: " & Str(Err.Number) & vbNewLine & _
            Err.Description & vbNewLine & _
            "Call technical support."
End Select

MsgBox _
    Title:="XXX Tools", _
    Prompt:=strErrorText, _
    Buttons:=vbInformation
GoTo Done

Done:

Set objSection = Nothing
Set objHeaderFooter = Nothing

Application.ScreenUpdating = True
System.Cursor = wdCursorNormal

End Sub

~~~~~

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, visit the group's homepage and use the dropdown 
menu at the top.  This will allow you to unsubscribe your email address or 
change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to share files with the group, you must join our Yahoo sister group. 
 This group will not allow for posting of emails, but will allow you to join 
and share problem files, templates, etc.:  
http://tech.groups.yahoo.com/group/MicrosoftOffice . This group is for FILE 
SHARING ONLY.

If you are using Outlook and you see a lot of unnecessary code in your email 
messages, read these instructions that explain why and how to fix it:
http://personal-computer-tutor.com/abc3/v28/greg28.htm
*************************************************************

Other related posts: