I have the following code

Selection.WholeStory
Selection.Fields.Update

that i use to update fields, but it does not updatefields in the header and
footer.

I have tried adding

Selection.HeaderFooter

But gives an error (Ivalid use of property).

How can I update all the fields, not matter where they are?

Jan

Re: How to select whole document including header and foter by Jan

Jan
Fri Apr 15 06:19:36 CDT 2005

I got it myself:

This will do the job:

Sub FileSave()
ActiveDocument.Fields.Update
n = ActiveDocument.Sections.Count
For i = 1 To n
ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
Next i
ActiveDocument.save
End Sub

But I still wonder if it can done in an easier way.

Jan

"Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> skrev i en
meddelelse news:uGzi5NaQFHA.924@TK2MSFTNGP14.phx.gbl...
> I have the following code
>
> Selection.WholeStory
> Selection.Fields.Update
>
> that i use to update fields, but it does not updatefields in the header
and
> footer.
>
> I have tried adding
>
> Selection.HeaderFooter
>
> But gives an error (Ivalid use of property).
>
> How can I update all the fields, not matter where they are?
>
> Jan
>
>
>



Re: How to select whole document including header and foter by Jean-Guy

Jean-Guy
Fri Apr 15 07:57:04 CDT 2005

Jan Kronsell was telling us:
Jan Kronsell nous racontait que :

> I got it myself:
>
> This will do the job:
>
> Sub FileSave()
> ActiveDocument.Fields.Update
> n = ActiveDocument.Sections.Count
> For i = 1 To n
> ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
> ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
> Next i
> ActiveDocument.save
> End Sub
>
> But I still wonder if it can done in an easier way.

You could try:

Application.PrintPreview = True
Application.PrintPreview = False

The screen will flash, but it is fairly quick, this will also update the
fields in the document body. It will not work if Automatically update fields
is turned off in the print options, but this is on by default.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org




Re: How to select whole document including header and foter by Jan

Jan
Fri Apr 15 08:48:32 CDT 2005

Thanks, Ill try that.


Jan

"Jean-Guy Marcil" <no-spam@leaveme.alone> skrev i en meddelelse
news:up$xhqbQFHA.3716@TK2MSFTNGP14.phx.gbl...
> Jan Kronsell was telling us:
> Jan Kronsell nous racontait que :
>
> > I got it myself:
> >
> > This will do the job:
> >
> > Sub FileSave()
> > ActiveDocument.Fields.Update
> > n = ActiveDocument.Sections.Count
> > For i = 1 To n
> > ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
> > ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
> > Next i
> > ActiveDocument.save
> > End Sub
> >
> > But I still wonder if it can done in an easier way.
>
> You could try:
>
> Application.PrintPreview = True
> Application.PrintPreview = False
>
> The screen will flash, but it is fairly quick, this will also update the
> fields in the document body. It will not work if Automatically update
fields
> is turned off in the print options, but this is on by default.
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>
>
>



Re: How to select whole document including header and foter by Charles

Charles
Fri Apr 15 08:54:42 CDT 2005

Much better is the macro at http://www.gmayor.com/installing_macro.htm. This
will pick up all headers/footers.
--
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.

"Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> wrote in message
news:uNUpiyaQFHA.3596@TK2MSFTNGP15.phx.gbl...
>I got it myself:
>
> This will do the job:
>
> Sub FileSave()
> ActiveDocument.Fields.Update
> n = ActiveDocument.Sections.Count
> For i = 1 To n
> ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
> ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
> Next i
> ActiveDocument.save
> End Sub
>
> But I still wonder if it can done in an easier way.
>
> Jan
>
> "Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> skrev i en
> meddelelse news:uGzi5NaQFHA.924@TK2MSFTNGP14.phx.gbl...
>> I have the following code
>>
>> Selection.WholeStory
>> Selection.Fields.Update
>>
>> that i use to update fields, but it does not updatefields in the header
> and
>> footer.
>>
>> I have tried adding
>>
>> Selection.HeaderFooter
>>
>> But gives an error (Ivalid use of property).
>>
>> How can I update all the fields, not matter where they are?
>>
>> Jan
>>
>>
>>
>
>



Re: How to select whole document including header and foter by Jan

Jan
Fri Apr 15 09:14:00 CDT 2005

Unfortunately the link doesn't work on my computer.

I have

Jan

"Charles Kenyon" <msnewsgroup@remove.no.spam.addbalance.com> skrev i en
meddelelse news:#VfMnKcQFHA.3664@TK2MSFTNGP15.phx.gbl...
> Much better is the macro at http://www.gmayor.com/installing_macro.htm.
This
> will pick up all headers/footers.
> --
> 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.
>
> "Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> wrote in message
> news:uNUpiyaQFHA.3596@TK2MSFTNGP15.phx.gbl...
> >I got it myself:
> >
> > This will do the job:
> >
> > Sub FileSave()
> > ActiveDocument.Fields.Update
> > n = ActiveDocument.Sections.Count
> > For i = 1 To n
> > ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
> > ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
> > Next i
> > ActiveDocument.save
> > End Sub
> >
> > But I still wonder if it can done in an easier way.
> >
> > Jan
> >
> > "Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> skrev i en
> > meddelelse news:uGzi5NaQFHA.924@TK2MSFTNGP14.phx.gbl...
> >> I have the following code
> >>
> >> Selection.WholeStory
> >> Selection.Fields.Update
> >>
> >> that i use to update fields, but it does not updatefields in the header
> > and
> >> footer.
> >>
> >> I have tried adding
> >>
> >> Selection.HeaderFooter
> >>
> >> But gives an error (Ivalid use of property).
> >>
> >> How can I update all the fields, not matter where they are?
> >>
> >> Jan
> >>
> >>
> >>
> >
> >
>
>



Re: How to select whole document including header and foter by Chuck

Chuck
Fri Apr 15 09:50:01 CDT 2005

This works for me. Note that I've included the MakeHFValid public sub which
ensures that all headers/footers are activated storyranges for editing (per
the MVPS website):

Sub UpdateAllFields()

Dim rngRange As Range

With ActiveDocument

.Fields.Update

For Each rngRange In ActiveDocument.StoryRanges
Do
rngRange.Fields.Update
Set rngRange = rngRange.NextStoryRange
Loop Until rngRange Is Nothing
Next

End With

End Sub

Public Sub MakeHFValid()
'
'Required for global find and replace to make sure HeadersFooters StoryRange
is activated
'
Dim lngJunk As Long
Dim hdrHeader As HeaderFooter
Dim i As Integer

For i = 1 To ActiveDocument.Sections.Count
For Each hdrHeader In ActiveDocument.Sections(i).Headers
lngJunk = hdrHeader.Range.StoryType
Next hdrHeader
Next i

End Sub


"Jan Kronsell" wrote:

> I got it myself:
>
> This will do the job:
>
> Sub FileSave()
> ActiveDocument.Fields.Update
> n = ActiveDocument.Sections.Count
> For i = 1 To n
> ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
> ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
> Next i
> ActiveDocument.save
> End Sub
>
> But I still wonder if it can done in an easier way.
>
> Jan
>
> "Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> skrev i en
> meddelelse news:uGzi5NaQFHA.924@TK2MSFTNGP14.phx.gbl...
> > I have the following code
> >
> > Selection.WholeStory
> > Selection.Fields.Update
> >
> > that i use to update fields, but it does not updatefields in the header
> and
> > footer.
> >
> > I have tried adding
> >
> > Selection.HeaderFooter
> >
> > But gives an error (Ivalid use of property).
> >
> > How can I update all the fields, not matter where they are?
> >
> > Jan
> >
> >
> >
>
>
>

Re: How to select whole document including header and foter by Jan

Jan
Fri Apr 15 17:24:40 CDT 2005

Thank you all for your help.

I have an additional question though. When a user closes a document that has
not previously been saved, he is asked if he wants to save it or not, How do
I test what key the user uses?

I guess it must be sometinh like

If something = vbYes

but what is something? And what should I call my sub to catch it? I tried
with FileClose and FileQuit but to no use.

Jan


"Chuck" <Chuck@discussions.microsoft.com> skrev i en meddelelse
news:34F00A10-96CD-4EC2-BFD9-FAE7D73D853A@microsoft.com...
> This works for me. Note that I've included the MakeHFValid public sub
which
> ensures that all headers/footers are activated storyranges for editing
(per
> the MVPS website):
>
> Sub UpdateAllFields()
>
> Dim rngRange As Range
>
> With ActiveDocument
>
> .Fields.Update
>
> For Each rngRange In ActiveDocument.StoryRanges
> Do
> rngRange.Fields.Update
> Set rngRange = rngRange.NextStoryRange
> Loop Until rngRange Is Nothing
> Next
>
> End With
>
> End Sub
>
> Public Sub MakeHFValid()
> '
> 'Required for global find and replace to make sure HeadersFooters
StoryRange
> is activated
> '
> Dim lngJunk As Long
> Dim hdrHeader As HeaderFooter
> Dim i As Integer
>
> For i = 1 To ActiveDocument.Sections.Count
> For Each hdrHeader In ActiveDocument.Sections(i).Headers
> lngJunk = hdrHeader.Range.StoryType
> Next hdrHeader
> Next i
>
> End Sub
>
>
> "Jan Kronsell" wrote:
>
> > I got it myself:
> >
> > This will do the job:
> >
> > Sub FileSave()
> > ActiveDocument.Fields.Update
> > n = ActiveDocument.Sections.Count
> > For i = 1 To n
> > ActiveDocument.Sections(i).Headers(1).Range.Fields.Update
> > ActiveDocument.Sections(i).Footers(1).Range.Fields.Update
> > Next i
> > ActiveDocument.save
> > End Sub
> >
> > But I still wonder if it can done in an easier way.
> >
> > Jan
> >
> > "Jan Kronsell" <kronsell(removebeforesend)@adslhome.dk> skrev i en
> > meddelelse news:uGzi5NaQFHA.924@TK2MSFTNGP14.phx.gbl...
> > > I have the following code
> > >
> > > Selection.WholeStory
> > > Selection.Fields.Update
> > >
> > > that i use to update fields, but it does not updatefields in the
header
> > and
> > > footer.
> > >
> > > I have tried adding
> > >
> > > Selection.HeaderFooter
> > >
> > > But gives an error (Ivalid use of property).
> > >
> > > How can I update all the fields, not matter where they are?
> > >
> > > Jan
> > >
> > >
> > >
> >
> >
> >