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

Word footers not different for different sections 1

Status
Not open for further replies.

Madawc

Programmer
Sep 5, 2002
7,628
GB
In Word 2002 under Windows XP, I frequently use next-page section-breaks, mostly so that some pages can be landscape within a document that is mostly portrait.

Normally this works fine, apart from headers and footers. These are always identified as belonging to that section. But sometimes a change to the header or footer in one section changes the whole document. Sometimes it does not. And I haven't been able to work out the logic for this.

I have looked at Page Setup, which does mention rules for headers and footers and whether they should apply to the whole document or just this section. But it doesn't seem to apply to matters of text and layout, which is what I'd like to control.

Madawc Williams (East Anglia)
 
I suspect you're falling foul of the "Same as Previous" conundrum. If it is set as on any change in one footer will alter all the rest, otherwise you can set any footer you like per section.

Check that first as I think this might answer your question.

Asjeff
 
Thanks, it may well be the problem. I've never heard of a Same as Previous in connection with footers and have no idea of how to check it.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
This seems to be coming yp a lot lately. I am writing a FAQ on this subject.

Essentially, there are ALWAY three headers in rach section.

wdHeaderFooterPrimary
wdHeaderFooterFirstPage
wdJeaderFooterEvenPage.

There is no OddPage.There are two sitiation, basically.

Scenario 1.

Page Setup = NO Different first page; NO different odd and even.

In which case wdHeaderFooter shows as the header through the section.

wdHeaderFooter, in this case, is the first geader entered; regardless of the page number it is set on. Even page, Odd page, it does not matter, it becomes Primary.

Scenario 2

Page Set = Different first page, Different odd and even.

wdHeaderFooterPrimary is the header entered from an odd page, first page is the first page, even page is from an even page.

NOTE is you revert back to NO difference, the header shown is what was the odd page - because there IS no odd page, what was Odd becomes Primary, and that is what will show.

It is always a good idea to explicitly set headers IMMEDIATELY upon making a section. Insert two blank pages and set first / odd /even. The selete the pages. The text is stored as properties of the THREE header objects that are ALWAYS in a section.

Explicitly tun off Same as previous. you can always tun it back on. This aagin sets explicitly headers for the section, which are stored in the Section objects.

Going back and putting in text, BEFORE geteting rid of Same as previous removes the same as previous, but pulls the previous back up to the (later) current header.

Again, it is best practives to create the possibly header immediately. Going backwards cause confusion and much hair pulling.

The logic is this.

the Primary header is:

a) with no diiferences between first, or odd/even pages, is set by the FIRST header entered, regardless of apparent page number (odd/even)

b) with differences, set is set from the header entered from an odd page.

Once set to ANYTHING, the only way to change the Primary is:

a) with no differences, set by any page header

b) with differences, set by changing from an odd page.

If there were differences, thus creating possible separate text for FirstPage, OddPage, EvenPage, and these are stored as HeaderFooter object properties in the Section object. If there were differences, then difference removed, the headers would show as what was the odd page. Programatically, if you do an:

ActiveDocument.Sections(2).Headers(2).Range.Text

thus returning the Range.Text of Index 2 of the headers collection, of Section 2, you would get:

wdHeaderFooterFirstPage

Even though the page setup was set up to NO difference, and the header SHOWN is wdHeaderFooterPrimary, or what was Odd page, programatically, what is returned is still wdHeaderFootFirstPage if it contains a value > "".

This can not be emphasized enough. There is NO odd page header, there is Primary.

You should always, when making a new section, insert two new page breaks (Ctrl_Enter NOT section break next page!). Set the headers, and delete the pages. Any new real estate added to that section (with Same as previous turned off) will automatically fill in with the proper header. Any expansion that cause new pages within the section ( by typing text or insert text) will pick up the proper header stored in the Section.

To reply to your statement:
Page Setup, which does mention rules for headers and footers and whether they should apply to the whole document or just this section. But it doesn't seem to apply to matters of text and layout, which is what I'd like to control.

They do not directly apply to matter of text and layout. They do not create values in the three header objects, they USE them.

If you have something specific you wish assistance on, post here.

Please be specific. Application abd Version. What exactly problems have occured?

Gerry
 
Thanks for your detailed reply, fumei.

The document that gave me trouble has two sections, the first of which has a different first page. The second section has landscape layout. Neither use odd/even

I found that the page number was missing on the first section of the document - which I was updating, someone else created it. I got the page number back by adjusting the tabs, but then it looked cramped on the second section.

I tried to adjust the tabs on the second section to fit the wider page. But it refuses to make changes for just that section alone.

So how to I proceed?

I could in fact leave it as it is, but there are also cases where there is a more important difference between sections and a modified header or footer would be useful.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Please clarify the "tab" reference? Thanks. It confused me.

You may also wish to check out: thread707-924325, which mentions some more detail on header/footer objects. It is a little tricky getting what is actually happening in the Word Object Model, but once you do, headers and footer are MUCH less a problem.

OK. For heaven sake...use styles!!!!!! I can not stress this enough. In my documents, no matter how long they are ( I commonly have 600 page technical documents), there is not one, not a single case of Normal style. Not one.

It can make for quite a number of styles (some documents have 70 or 80 styles...or more). However, using styles, once set up (and of course development work is always four times the production work) having the styles makes thing deliberate, designed, and explicit.

Here is a real work example. There are three textual area in the header. Plus the document is setup for Different first page, odd and even.

wdHeaderFooterPrimary ( therefore what shows on ODD Pages)

Word - VBA and Advanced Techniques (left side of header - uses HeaderTitle style - Arial, 12 pts Bold))

Module 5 - Using Range and Selection Objects
(right side of header, uses HeaderModule style = Times Roman, 11 points, italics))

Instructor Guide (left of header, on new line - uses HeaderDocType as style)

These have three styles, and I NEVER do manual formatting.

wdHeaderFooterFirstPage

Blank. This is start of a new chapter, and has a ChapterHeading style and a header looks stupid.

wdHeaderFooterEvenPage (what shows on even pages)

Module 5 - Using Range and Selection Objects
(left side of header)

Word - VBA and Advanced Techniques ([b[right[/b] side of header)

Instructor Guide (right side of header, on new line)

I can still use the format of the appropriate styles.

In rare occasions I will use Same as Prvious - for example in my wdHeaderFooterFirstPage - they are always blank...what the heck I set them as Same as Previous, However, I srtrongly recommend always unselecting Same as previous, and explicitly setting up each of the header objects , REGARDLESS OF WHETHER YOU ARE GOING TO USE THEM OR NOT.

The vast majority of problems I have seen people have with headers results from a failure to grasp this, admitedly convoluted way that Word deals with headers.

Gerry
 
Fuemi, if I've understood you correctly, the creators of Microsoft Word decided we could have primary header/footers, along with an alternate header/footers for the first page and another alternate header/footers for the even pages?

This means that I am wasting my time trying to ger different header/footers for sections - I could maybe fiddle it using 'first page', but Word does not allow it as a general method. Thanks, that's worth a star and I'll live with what I've got.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
No, no. You CAN, absolutely get different headers/footers for different sections. No problem.

EACH section has a Primary, First Page, and Even header/footer. Each section always has those three, regardless of if they are used, or not. So different Sections have their own Primary, First Page and Even. This is NOT a problem.

The problem lies in that the DEFAULT setting when new sections are made is "Same as previous". Word assumes that the headers and footers are NOT going to be different.

So, OK you have two sections, one portrait, and one landscape.

Section 1 has: Different first page, but no odd/even.
Section 2 has: a different header/footer from Section 1, but NO different first page, and no odd/even.

If your text is simple, use this code. Obviously you will want to change the actual text I put here. I hopefully commented enough so it is clear what is going on. Note that you do NOT have to go through the whole opening header/footer viewing panes and all that crap. You can directly write and read headers data, using the specific objects.

Code:
Sub FixHeaders()

' go to start of document
    Selection.HomeKey Unit:=wdStory
' do page setup for current section
    With Selection.PageSetup
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = True
    End With
' go to next section
    Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext, Count:=1, Name:=""
' do page setup for current section
    With Selection.PageSetup
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
    End With

With ActiveDocument
'  explicitly write Section 1 headers for Primary and First Page
   With .Sections(1)
     .Headers(wdHeaderFooterPrimary).Range.Text = _
        "This is NOT the Section 1 first page header text.  It is the other pages header."
     .Headers(wdHeaderFooterFirstPage).Range.Text = _
        "This IS the Section 1 First Page header text."
    End With

'  explicitly write Section 2 header = Primary
    With .Sections(2)

' IMPORTANT!!!  the following makes the Primary NOT 
' Same as previous
' IMPORTANT!!!  this ONLY makes the [b]Primary[/b] not 
' Same as previous
' if ever this section is changed to have different 
' first page, or different odd even, they will be 
' Same as previous, and it will likely mess things up.
' to make ALL headers in the Section unlinked, use:
'  .Headers().Item().LinkToPrevious = False
        
    .Headers().Item(wdHeaderFooterPrimary).LinkToPrevious = False
    .Headers(wdHeaderFooterPrimary).Range.Text = _
        "This is the header text for Section 2."
  End With
End With
End Sub

This is assuming you have already set up the landscape aspect of section 2. Other than that, it should with your own replacement text), write a first page header (Section 1), a header for all other pages (Section 1), unlink the header for section 2, then write a header for Section 2 that applies to all pages of that Section.

I know headers and footers are a bit strange. However, once you grasp it, they are not difficult anymore. Still strange, but not difficult.

Gerry
 
This all involves writing Macros for the document, right? I was hopping there was some simpler way.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Oh, well sure. You can do all of it manually. Just follow the steps manually. You have to work backwards.

1. Go to Section 2, do Page Setup and uncheck Different first page, and uncheck Different odd/even. Make sure that the "Applies to" is set for "This Section".

2. Still in Section 2, go into View > Header Footer, and make sure the header is set to NOT Same as previous.

3. Make the header whatever it is you want.

4. Exit out of View Header Footer

4. Go to Section 1, do PageSetup and check Different first page. Make sure the "Applies to" is set for "This Section"

5. Go into View > Header Footer and move the header view to "First Page Section 1" (this shows at the top of the header text area). Enter whatever it is you want for the first page.

6. Move to the next header text area. To advance click the "Show Next" button (right beside the Close button on the header/footer toolbar). The header should state "Header Section 1".

7. Enter the text for the other pages of Section 1.

Gerry
 
Thanks, that's what I was after. Just clicking the Same As Previous icon in the header/footer toolbar makes or breaks the connection.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top