PDA

View Full Version : Updating Fields on a save


jwknock
November 24th 04, 02:05 PM
Trying to create a template which holds the filename in the header. If you
save the document under a new name the filename field will only update on
printing if the box is ticked in Tools, Options, Printing. I would like to
force the field to update as soon as file is saved. I realise this possibly
should come under "programming" topic.

Jezebel
November 24th 04, 08:35 PM
You'll need to write some code --

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

That update all fields in your document, wherever they're located. (Apart
from headers and footers, fields in textboxes and footnotes also need to be
updated separately.)




"jwknock" > wrote in message
...
> Trying to create a template which holds the filename in the header. If you
> save the document under a new name the filename field will only update on
> printing if the box is ticked in Tools, Options, Printing. I would like to
> force the field to update as soon as file is saved. I realise this
possibly
> should come under "programming" topic.

jwknock
November 25th 04, 12:33 PM
Thanks, I thought it would be something like that, where I'm stumped is how
to capture a SAve or Save as so I can do that update as soon as the user
saves the file under a new name.

"Jezebel" wrote:

> You'll need to write some code --
>
> 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
>
> That update all fields in your document, wherever they're located. (Apart
> from headers and footers, fields in textboxes and footnotes also need to be
> updated separately.)
>
>
>
>
> "jwknock" > wrote in message
> ...
> > Trying to create a template which holds the filename in the header. If you
> > save the document under a new name the filename field will only update on
> > printing if the box is ticked in Tools, Options, Printing. I would like to
> > force the field to update as soon as file is saved. I realise this
> possibly
> > should come under "programming" topic.
>
>
>

Greg Maxey
November 25th 04, 12:59 PM
Maybe something like:

Sub FileSaveAs()



Dialogs(wdDialogFileSaveAs).Show

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

System.Cursor = wdCursorNormal



End Sub

--
Greg Maxey/Word MVP
A Peer in Peer to Peer Support

jwknock wrote:
> Thanks, I thought it would be something like that, where I'm stumped
> is how to capture a SAve or Save as so I can do that update as soon
> as the user saves the file under a new name.
>
> "Jezebel" wrote:
>
>> You'll need to write some code --
>>
>> 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
>>
>> That update all fields in your document, wherever they're located.
>> (Apart from headers and footers, fields in textboxes and footnotes
>> also need to be updated separately.)
>>
>>
>>
>>
>> "jwknock" > wrote in message
>> ...
>>> Trying to create a template which holds the filename in the header.
>>> If you save the document under a new name the filename field will
>>> only update on printing if the box is ticked in Tools, Options,
>>> Printing. I would like to force the field to update as soon as file
>>> is saved. I realise this possibly should come under "programming"
>>> topic.

Jezebel
November 25th 04, 08:32 PM
You capture user instructions by writing a macro of the same name. In this
case FileSave and FileSaveAs.


"jwknock" > wrote in message
...
> Thanks, I thought it would be something like that, where I'm stumped is
how
> to capture a SAve or Save as so I can do that update as soon as the user
> saves the file under a new name.
>
> "Jezebel" wrote:
>
> > You'll need to write some code --
> >
> > 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
> >
> > That update all fields in your document, wherever they're located.
(Apart
> > from headers and footers, fields in textboxes and footnotes also need to
be
> > updated separately.)
> >
> >
> >
> >
> > "jwknock" > wrote in message
> > ...
> > > Trying to create a template which holds the filename in the header. If
you
> > > save the document under a new name the filename field will only update
on
> > > printing if the box is ticked in Tools, Options, Printing. I would
like to
> > > force the field to update as soon as file is saved. I realise this
> > possibly
> > > should come under "programming" topic.
> >
> >
> >

Google