Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DocVariable update in Header/Footer area

Status
Not open for further replies.

JTrumpfheller

Programmer
Dec 8, 2005
2
DE
Hy people,

my first q: here and hope to get an answer.

I defined a template in word with a lot of fields and selfdefined docvariables.

In the maindocument I can set the values like this:

ActiveDocument.Variables(WhichField).Value = WhichValue

After I have set every value I can say:

ActiveDocument.Fields.Update

And I can see the result as I wanted it.

In the footer area I also have defined fields and docvariables but I have no idea how to update the fields so that the new item.values are shown. I can write the values with this:

With ActiveDocument.sections(1).Footers _
.Item(wdHeaderFooterFirstPage).Range
.Document.Variables(WhichField).Value = WhichValue
End With

But how to update/refresh it?

To do it manually I have to open the Header/Footer area - select the special field - right mouse - edit field - Ok and then the new value is shown. But how can I do it via vba?

To record a makro is not useful because you can not use the mouse and I didn't find the right mouse context menu in the main menu.

Thanks Joerg
 
Hi JTrumpfheller,

There are several possible solutions to this. Word documents consist of several Stories. Headers and Footers are separate stories from the main document body.

You can write code which loops through all the stories updating fields - I think Help has an example, but come back if you're stuck. Or, for just one footer, say, you can use ..

Code:
ActiveDocument.Sections(1).Footers(1).Range.Fields.Update

Also note that fields in headers and footers are treated slightly differently from fields in the main story. If you switch the view to Normal and back to Page Layout they will be automatically updated. And to manually update, all you need to do (with the view in the footer of course) is select all (ctrl+a) and press F9.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Thanks Tony,

this works for me. I didn't found it in the help or docu or elsewhere. I always tried it with
Code:
ActiveDocument.sections(1).Footers.Item(wdHeaderFooterFirstPage).Range.Fields.Update
ActiveDocument.sections(1).Footers.Item(wdHeaderFooterPrimary).Range.Fields.Update
because I use different footers
But the second part always gets an error message.

Joerg
 
What error message do you get?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top