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.