Hi,

I am looking for a VBA-Code to update all fields in a document.

The command "ActiveDocument.Fields.Update" does not update fields in headers
and footers and in text-fields.

In Word 2003 the following code does the job perfectly:
-------------------------------------------------------------
For Each Teil In ActiveDocument.StoryRanges
Teil.Fields.Update
While Not (Teil.NextStoryRange Is Nothing)
Set Teil = Teil.NextStoryRange
Teil.Fields.Update
Wend
Next
---------------------------------------------------------------

But in Word 2007 this code does not work. Fields in headers, footers an
text-fields will not update.
What happens here?

Does anybody have an idear how to consequently update all fields?

Regards Karl.

Re: Fields.Update does not work correctly in Word 2007 by Doug

Doug
Tue Mar 13 07:35:41 CDT 2007

Quick and dirty way is to use

With ActiveDocument
.PrintPreview
.ClosePrintPreview
End With
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Karl Zuern" <Karl.Zuern@DATA5.de> wrote in message
news:46362936-7E91-47AE-8E98-22B4122A4DDE@microsoft.com...
> Hi,
>
> I am looking for a VBA-Code to update all fields in a document.
>
> The command "ActiveDocument.Fields.Update" does not update fields in
> headers and footers and in text-fields.
>
> In Word 2003 the following code does the job perfectly:
> -------------------------------------------------------------
> For Each Teil In ActiveDocument.StoryRanges
> Teil.Fields.Update
> While Not (Teil.NextStoryRange Is Nothing)
> Set Teil = Teil.NextStoryRange
> Teil.Fields.Update
> Wend
> Next
> ---------------------------------------------------------------
>
> But in Word 2007 this code does not work. Fields in headers, footers an
> text-fields will not update.
> What happens here?
>
> Does anybody have an idear how to consequently update all fields?
>
> Regards Karl.



Re: Fields.Update does not work correctly in Word 2007 by Karl

Karl
Wed Mar 14 03:27:31 CDT 2007

Hi Doug,

good idea.

But it seems not to work. This updates fields in the header very well. But
it does not update Fields in the normal text or in text-fields. ????????

There is a word option "Update Fields before Printing", but this does not
change anything.

I use fields to show DOCVariables in the document. They do not update, when
the variable chances.
Sample:
{DOCVARIABLE "Copyright" \*MERGEFORMAT}

Updating of fields seems to be a great problem. I have found a lot of
statements in the web. But with Word 2007 no method seems to work correct.

Thanks for your help.
Regards Karl.




"Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> schrieb im Newsbeitrag
news:eGwSkwWZHHA.4368@TK2MSFTNGP06.phx.gbl...
> Quick and dirty way is to use
>
> With ActiveDocument
> .PrintPreview
> .ClosePrintPreview
> End With
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Karl Zuern" <Karl.Zuern@DATA5.de> wrote in message
> news:46362936-7E91-47AE-8E98-22B4122A4DDE@microsoft.com...
>> Hi,
>>
>> I am looking for a VBA-Code to update all fields in a document.
>>
>> The command "ActiveDocument.Fields.Update" does not update fields in
>> headers and footers and in text-fields.
>>
>> In Word 2003 the following code does the job perfectly:
>> -------------------------------------------------------------
>> For Each Teil In ActiveDocument.StoryRanges
>> Teil.Fields.Update
>> While Not (Teil.NextStoryRange Is Nothing)
>> Set Teil = Teil.NextStoryRange
>> Teil.Fields.Update
>> Wend
>> Next
>> ---------------------------------------------------------------
>>
>> But in Word 2007 this code does not work. Fields in headers, footers an
>> text-fields will not update.
>> What happens here?
>>
>> Does anybody have an idear how to consequently update all fields?
>>
>> Regards Karl.
>
>


Re: Fields.Update does not work correctly in Word 2007 by Stefan

Stefan
Wed Mar 14 05:03:02 CDT 2007

Does it work if run Doug's code *and* your code?

--
Stefan Blom
Microsoft Word MVP


"Karl Zuern" wrote in message
news:884B34A5-4651-43DB-A3C1-3BBA217793D7@microsoft.com...
> Hi Doug,
>
> good idea.
>
> But it seems not to work. This updates fields in the header very
well. But
> it does not update Fields in the normal text or in text-fields.
????????
>
> There is a word option "Update Fields before Printing", but this
does not
> change anything.
>
> I use fields to show DOCVariables in the document. They do not
update, when
> the variable chances.
> Sample:
> {DOCVARIABLE "Copyright" \*MERGEFORMAT}
>
> Updating of fields seems to be a great problem. I have found a lot
of
> statements in the web. But with Word 2007 no method seems to work
correct.
>
> Thanks for your help.
> Regards Karl.
>
>
>
>
> "Doug Robbins - Word MVP" <dkr@REMOVECAPSmvps.org> schrieb im
Newsbeitrag
> news:eGwSkwWZHHA.4368@TK2MSFTNGP06.phx.gbl...
> > Quick and dirty way is to use
> >
> > With ActiveDocument
> > .PrintPreview
> > .ClosePrintPreview
> > End With
> > --
> > Hope this helps.
> >
> > Please reply to the newsgroup unless you wish to avail yourself of
my
> > services on a paid consulting basis.
> >
> > Doug Robbins - Word MVP
> >
> > "Karl Zuern" <Karl.Zuern@DATA5.de> wrote in message
> > news:46362936-7E91-47AE-8E98-22B4122A4DDE@microsoft.com...
> >> Hi,
> >>
> >> I am looking for a VBA-Code to update all fields in a document.
> >>
> >> The command "ActiveDocument.Fields.Update" does not update fields
in
> >> headers and footers and in text-fields.
> >>
> >> In Word 2003 the following code does the job perfectly:
> >> -------------------------------------------------------------
> >> For Each Teil In ActiveDocument.StoryRanges
> >> Teil.Fields.Update
> >> While Not (Teil.NextStoryRange Is Nothing)
> >> Set Teil = Teil.NextStoryRange
> >> Teil.Fields.Update
> >> Wend
> >> Next
> >> ---------------------------------------------------------------
> >>
> >> But in Word 2007 this code does not work. Fields in headers,
footers an
> >> text-fields will not update.
> >> What happens here?
> >>
> >> Does anybody have an idear how to consequently update all fields?
> >>
> >> Regards Karl.
> >
> >
>





the solution .... by Karl

Karl
Wed Mar 14 06:07:34 CDT 2007

thanks to Stefan and Doug!
Stefan, you are right! The combination of both codes works!

But now, I found a solution without switching to Print-Preview. This
solution should »really« update all fields in the document (hopefully).

---------------------------------------------------
Sub UpdateAllFields()
'Update all fields in all parts of the document
' in Maintext, in footer / Headers, in textboxes
' and also in textboxes inside footers and headers
Dim aRange As Range
Dim aShape As Shape

Application.ScreenUpdating = False
'Update filds in alle Parts of the document (Header, Footer etc...)
For Each aRange In ActiveDocument.StoryRanges
aRange.Fields.Update

'------------------------
'Fields.Update does not work, if fields are inside textboxes, when the
Textbox is inside a footer / header
'to fix this separatly handle the Textboxes (ShapeRange)
For Each aShape In aRange.ShapeRange
With aShape.TextFrame
If .HasText Then
.TextRange.Fields.Update
End If
End With
Next aShape
'------------------------

While Not (aRange.NextStoryRange Is Nothing)
Set aRange = aRange.NextStoryRange
aRange.Fields.Update
Wend
Next
Application.ScreenUpdating = True

End Sub

-----------------------------------------------------

Hope, this helps some other people, too.

Regards Karl.























"Karl Zuern" <Karl.Zuern@DATA5.de> schrieb im Newsbeitrag
news:46362936-7E91-47AE-8E98-22B4122A4DDE@microsoft.com...
> Hi,
>
> I am looking for a VBA-Code to update all fields in a document.
>
> The command "ActiveDocument.Fields.Update" does not update fields in
> headers and footers and in text-fields.
>
> In Word 2003 the following code does the job perfectly:
> -------------------------------------------------------------
> For Each Teil In ActiveDocument.StoryRanges
> Teil.Fields.Update
> While Not (Teil.NextStoryRange Is Nothing)
> Set Teil = Teil.NextStoryRange
> Teil.Fields.Update
> Wend
> Next
> ---------------------------------------------------------------
>
> But in Word 2007 this code does not work. Fields in headers, footers an
> text-fields will not update.
> What happens here?
>
> Does anybody have an idear how to consequently update all fields?
>
> Regards Karl.