Update Fields within a TextBox within a Header

B

Brent McIntyre

Good evening all,

I am having trouble updating fields automatically that are within a TextBox within a Header of a Document Template. I have been using the standard update programming shown within Microsoft Word Visual Basic Help ie.

If ActiveDocument.Fields.Update = 0 Then
MsgBox "Update Successful"
Else
MsgBox "Field " & ActiveDocument.Fields.Update & _
" has an error"
End If

This has worked fine when the field is within a document, but it has now ceased to work.

Any assistance you may be able to provide would be greatly appreciated.

Yours sincerely,

Brent McIntyre
 
J

Jezebel

To update all the fields in a document, wherever they are location, use code
like this:

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



Brent McIntyre said:
Good evening all,

I am having trouble updating fields automatically that are within a
TextBox within a Header of a Document Template. I have been using the
standard update programming shown within Microsoft Word Visual Basic Help
ie.
 
B

Brent McIntyre

Jezebel,

Thanks for the tip I will give it a try !

Yours sincerely,

Brent McIntyre
 
D

Derek

Hi Jezebel.
I have the same challenge as Brent. I'm trying to update docvariable fields
within text boxes that are located in headers/footers.
The code you provided updates all fields except for my docvariable fields
within textboxes that are located in headers/footers.
I am at a loss.
best wishes from Western Canada
sugarborosnerd
....
 
J

Jezebel

This will do it --

Dim pRange As Word.Range
Dim pShape As Word.Shape

On Error Resume Next
For Each pRange In ActiveDocument.StoryRanges
Do
pRange.Fields.Update
For Each pShape In pRange.ShapeRange
pShape.TextFrame.TextRange.Fields.Update
Next
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
on error goto 0

The 'on error resume next' is needed because the ShapeRange reference throws
an error for some storyranges.
 
D

Derek

Jezebel, yes it does. I can't thank you enough.

best wishes from Western Canada,
/Derek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top