Hello,
Can someone tell me if I can hook into the save event. For some reason
fields located in my header and footer don't update when I do: CTRL+A;
F9. So on a save event, I want to add the code that will find all
fields and update them.
Thanks,
Craig H.
Hi,
Tony, Greg: thanks for your answers. I've taken advice from both and
here's what I came up with.
The only issue remaining is if I update a field then use "Save As...",
the newly saved doc doesn't display the most recent changes in the
field. I could solve my problem by knowing how to kick off the "Save
As..." with vba, after calling my UpdateFields_ method.
Any help is appreciated,
Craig.
Sub AutoNew()
ApplyTemplateSettings_
End Sub
Sub AutoOpen()
ActiveWindow.Caption = ActiveDocument.FullName 'Display filename
and path in window title bar
UpdateFields_
ApplyTemplateSettings_
End Sub
Sub FileSave()
UpdateFields_
ActiveDocument.Save
End Sub
Sub UpdateFields_()
Dim pRange As Word.Range
For Each pRange In ActiveDocument.StoryRanges
Do
pRange.Fields.Update
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
ActiveDocument.AttachedTemplate.Saved = True
End Sub
Sub ApplyTemplateSettings_()
ActiveWindow.ActivePane.DisplayRulers = True 'display the rulers
ActiveWindow.ActivePane.View.ShowAll = False 'turn off the
formatting command view
With ActiveWindow.View
.Type = wdPrintView 'select page/print layout view
'.Type = wdNormalView 'Alternative to the above line if normal
view is preferred
.Zoom.Percentage = 100 'set the display zoom to 100%
.FieldShading = wdFieldShadingWhenSelected 'set the field
shading preference
.ShowFieldCodes = False 'turn off field code display
.DisplayPageBoundaries = True 'Turn on white space between pages
End With
CommandBars("Reviewing").Visible = False 'Turn off the reviewing
toolbar
Options.UpdateFieldsAtPrint = True 'Update fields before printing
Options.UpdateLinksAtPrint = True 'Update links before printing
'CustomizationContext = NormalTemplate
CustomizationContext = ActiveDocument.AttachedTemplate
Set kbTemp = KeyBindings.Key(BuildKeyCode(wdKeyF9))
If (kbTemp Is Nothing) Then
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF9), _
KeyCategory:=wdKeyCategoryMacro, Command:="UpdateFields_"
Else
FindKey(BuildKeyCode(wdKeyF9)).Disable
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF9), _
KeyCategory:=wdKeyCategoryMacro, Command:="UpdateFields_"
End If
ActiveDocument.AttachedTemplate.Saved = True
End Sub