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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Probably a Simple Header/Footer Question

Status
Not open for further replies.

mike718

Programmer
Jul 7, 2004
58
US
There is probably a very simple solution to what I am trying to. I am just trying to pull data from a Header and set it to a variable of type String. I have tried many different ways of doing it but nothing seems to work for me. Could you please advise?
 
ms word is what i am having a problem with
 
Short answer is yes, you can. Header are dangerous territory though.

Please be clear on exactly what you what to do.

1. Is there more than one section in the document?

2. Is the document setup with different first page, different odd/even pages for the header.

The reason I ask, is that not many realize that there is no Odd page header - even if you have the document set up for different odd/even headers.

There are always three (3) headers in each section, regardless of the page setup.

wdHeaderFooterPrimary
wdHeaderFooterFirstPage
wdHeaderFooterEvenPage

The first header entered, regardless of the odd/even number of the page, is set as Primary. This becomes the Odd page header, IF the document is set for different odd/even. Otherwise it is the header for all pages.
Code:
Dim strHeader As String
strHeader = ActiveDocument.Sections(1).Headers(1).Range.Text
sets the string variable to the text of wdHeaderFooterPrimary of the first Section.

The order is Primary, FirstPage, EvenPage. So,

Code:
ActiveDocument.Sections(1).Headers([b]2[/b]).Range.Text
returns the text of wdHeaderFooterFirstPage of the first Section.

It is important to note that if you have had different headers (odd/even), then changed it to NOT having different headers, the text values of the different headers are still there. You can retrieve them programatically, or if you reset the document to different headers again.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top