RE: Footer Update by karina
karina
Tue Oct 19 15:25:02 CDT 2004
Mary,
I assume you are using a Filename field to display the document name, or
possibly a built-in doc property field. If it is a Filename field, the field
will automatically update when the user switches to another view, such as
Print Preview, or when they Print the document. Typically, when I program for
an enterprise-wide solution, I encourage the users to become familiar with
the way Word works, so I don't have to program something like this. However,
this may not be an enterprise-wide document/template, and even if it is, that
may not work for you here.
To that end, a couple notes. The ActiveDocument.Fields.Update won't fly
because it will only address those fields found in the main document story
(i.e., not in headers & footers).
I am assuming, from reading the code, that the programming you had was
recorded. Regardless, the code was jumping in and out of headers & footers
using the Selection object (which references where the cursor is located),
which does not produce consistent results, rather than the Range object.
Also, it counts on having a a specific set of headers & footers in a
document, which may not be the case if someone messes with the section
breaks, etc.
Following is some code you can use which will cycle through all the headers
and footers in the document, regardless of the type of header or footer, and
for each section, and will update the fields.
Dim objField As Field
Dim secSection As Section
For Each secSection In ActiveDocument.Sections
With secSection
'Update all the fields in the headers/footers
If .Headers(wdHeaderFooterFirstPage).Exists Then
.Headers(wdHeaderFooterFirstPage).Range.Fields.Update
End If
If .Headers(wdHeaderFooterEvenPages).Exists Then
.Headers(wdHeaderFooterEvenPages).Range.Fields.Update
End If
If .Headers(wdHeaderFooterPrimary).Exists Then
.Headers(wdHeaderFooterPrimary).Range.Fields.Update
End If
If .Footers(wdHeaderFooterFirstPage).Exists Then
.Footers(wdHeaderFooterFirstPage).Range.Fields.Update
End If
If .Footers(wdHeaderFooterEvenPages).Exists Then
.Footers(wdHeaderFooterEvenPages).Range.Fields.Update
End If
If .Footers(wdHeaderFooterPrimary).Exists Then
.Footers(wdHeaderFooterPrimary).Range.Fields.Update
End If
End With
Next secSection
I sure hope this does it for you! I know how frustrating headers & footers
can be!
"Mary" wrote:
> Many thanks Ulf for the suggestion but still no joy - it
> will only update fields in the main doc not the footer
>
>
> >-----Original Message-----
> >Hi
> >Try using:
> >ActiveDocument.Fields.Update
> >
> >/ Ulf
> >
> >>-----Original Message-----
> >>Hi
> >>
> >>I have a footer in my word document which display the
> >>document title - when I change the document title it
> >does
> >>not update my footer automatically. I don't really want
> >>my users to have to open the footer and use F9
> >>
> >>I added this procedure which was working fine but I
> >guess
> >>I have accidentally changed something as it no longer
> >>works but shows me an error (No errors if I open the
> >>template but the following error msg if I open any docs
> >>based on the template) error msg is:- run time error
> 91 -
> >
> >>object variable or with not set
> >>
> >>Please see my code below
> >>
> >>Private Sub Document_Open()
> >>'move to page 2 of the document
> >>Selection.HomeKey unit:=wdStory
> >>Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext,
> >>Count:=1
> >>'update fields in the header
> >>ActiveWindow.ActivePane.View.SeekView =
> >>wdSeekCurrentPageHeader
> >>Selection.HeaderFooter.LinkToPrevious = True
> >>Selection.WholeStory
> >>Selection.Fields.Update
> >>'update fields in the footer
> >>ActiveWindow.ActivePane.View.SeekView =
> >>wdSeekCurrentPageFooter
> >>Selection.HeaderFooter.LinkToPrevious = False
> >>Selection.WholeStory
> >>Selection.Fields.Update
> >>'Close Header Footer view & return to the top of the doc
> >>ActiveWindow.ActivePane.View.SeekView =
> >wdSeekMainDocument
> >>Selection.HomeKey unit:=wdStory
> >>End Sub
> >>
> >>.
> >>
> >.
> >
>