OddAndEvenPagesHeaderFooter

C

ccrites

Hello,

I'm having a very strange problem with .OddAndEvenPagesHeaderFooter. I
need to have the setting in my document as I want odd pages to be
formatted to right align and the opposite for even pages. Anyway,
whenever I execute this line of code:

Selection.PageSetup.OddAndEvenPagesHeaderFooter = True

I get three extra blank pages added into my document. I can't figure
out why this is happening. The only problem I can think of is that
this line of code is getting executed after there is already 5 or 6
preceding pages in the document that have the setting set to false.
Possibly this line of code is resetting their settings and adding in
pages when Word sees that their headers and footers are not different.

If this is the case, how do I make this setting only applicable to the
pages following these 5 or 6. And if this is not the case, what is the
problem?

Thanks in advance. Casey.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Hello,

I'm having a very strange problem with .OddAndEvenPagesHeaderFooter.
I need to have the setting in my document as I want odd pages to be
formatted to right align and the opposite for even pages. Anyway,
whenever I execute this line of code:

Selection.PageSetup.OddAndEvenPagesHeaderFooter = True

As written, this probably affects the whole document.
To affect only the current section, try this instead:
Selection.Sections(1).PageSetup.OddAndEvenPagesHeaderFooter = True
But see below first.
I get three extra blank pages added into my document. I can't figure
out why this is happening. The only problem I can think of is that
this line of code is getting executed after there is already 5 or 6
preceding pages in the document that have the setting set to false.
Possibly this line of code is resetting their settings and adding in
pages when Word sees that their headers and footers are not different.

Possibly?
It is your document after all.
Can't you tell where the extra pages are?
If this is the case, how do I make this setting only applicable to the
pages following these 5 or 6. And if this is not the case, what is
the problem?

Also, you probably have the current section's headers and footers set to be
identical to the previous one.
Break that connection before doing any changes.

For example:

Selection.Sections(1).Headers(wdHeaderFooterPrimary).LinkToPrevious = False

Finally, you are not telling us how many sections there are in your document
to start with.
If you want this setting to take effect only after page 6, but have only one
section, you will need to insert a section break first.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

ccrites

The first 5 pages are each their own sections, so when this new section
is added it is section 6. As for the links to previous, they have all
been broken. As for where the pages are added in, they are after page
1 (section 1, page 2), after old page 2 (section 2, page 2), after old
page 5 (section 5, page 2) and after a blank spacer page I added at the
end of the 5 sections (section 6, page 2).

The first two make sense to me as they are adding in a second page to
the first two sections, so that there are and odd and an even page.
However, I don't understand why it skips sections 3 and 4 (But it's
probably because there OddAndEven settings are set to false and the
others were True) and then picks up again at section 5 and 6.

Anyway, I guess what I need to know is how to use page setup from 'This
Point Forward' as I see there is a checkbox to do on the dialog box.
Any help there?
 
D

Dave Lett

If you have "even page" or "odd page" as your section break, then you might
be adding "pages" that way.

HTH,
Dave
 
C

ccrites

For my section breaks, I am only using 'wdSectionBreakNextPage' and
there is one after each of the first 6 pages before I try to run this
code on the 7th page. The line of code that is giving me problems
comes directly after one of those breaks (at the end of the 6th) and I
have tried

Selection.Sections(1).PageSetup...,
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup...
and
ActiveDocument.Sections(Section#).PageSetup...

and nothing seems to be working. Every single one of these will grab
the entire document and add a second blank page to sections where the
'OddAndEvenPagesHeaderFooter' setting is True. However, it skips those
that are set to false. What am I doing wrong here?
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
For my section breaks, I am only using 'wdSectionBreakNextPage' and
there is one after each of the first 6 pages before I try to run this
code on the 7th page. The line of code that is giving me problems
comes directly after one of those breaks (at the end of the 6th) and I
have tried

Selection.Sections(1).PageSetup...,
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup...
and
ActiveDocument.Sections(Section#).PageSetup...

and nothing seems to be working. Every single one of these will grab
the entire document and add a second blank page to sections where the
'OddAndEvenPagesHeaderFooter' setting is True. However, it skips
those that are set to false. What am I doing wrong here?

As I wrote before... Have you tried using
.LinkToPrevious = False
immediately after inserting the new section, but before making any changes
to the new section?

If you do try, and it still does not work, can you post the exact code you
used and a description of the document content before executing the code?

_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
For my section breaks, I am only using 'wdSectionBreakNextPage' and
there is one after each of the first 6 pages before I try to run this
code on the 7th page. The line of code that is giving me problems
comes directly after one of those breaks (at the end of the 6th) and I
have tried

Selection.Sections(1).PageSetup...,
ActiveDocument.Range(Start:=Selection.Start,
End:=ActiveDocument.Content.End).PageSetup...
and
ActiveDocument.Sections(Section#).PageSetup...

and nothing seems to be working. Every single one of these will grab
the entire document and add a second blank page to sections where the
'OddAndEvenPagesHeaderFooter' setting is True. However, it skips
those that are set to false. What am I doing wrong here?

Sorry, just started using my head on this one...
Never mind my previous post.

As soon as you use "different odd/even" in one section, it affects the whole
document.

But this in itself should not add blank pages, unless the type of section
breaks are changed.
What type of section breaks are used to delineate each section?
How about the new one?
Where is the cursor when you execute your code?

Post the exact code you are using.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

ccrites

I think this part should show you just what I'm doing. In addition to
this line:

With Selection.Sections(1).PageSetup

I have used the other ways that I described above. However, I'm still
getting the 4 pages put in. If you need to see more code then this,
I'll have to e-mail it to you as it's too big to post on a board.

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.InsertBreak Type:=wdSectionBreakNextPage
Selection.TypeParagraph

'make sure header and footer are not linked to previous
BREAK_HEADER_LINKS (IntSection)
BREAK_FOOTER_LINKS (IntSection)

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
IntSection = Selection.Information(wdActiveEndSectionNumber)

With Selection.Sections(1).PageSetup
.TopMargin = InchesToPoints(1.45)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.HeaderDistance = InchesToPoints(1)
.FooterDistance = InchesToPoints(1)
.OddAndEvenPagesHeaderFooter = True
.DifferentFirstPageHeaderFooter = True
End With

PS...This code was not written by me...these macros 'broke' and I have
been given the job of analyzing them, cleaning them up and hopefully
fixing them. So, sorry if there's default settings that don't need to
be there that I haven't gotten rid of yet.
 
C

ccrites

Sorry, I forgot to answer your questions.

All section breaks (including the new one) are as the one shown above,
wdSectionBreakNextPage.
The cursor is on section 7 (page 7). I thought this was the problem so
I added a few 'Selection.TypeParagraph' lines to get a visual and to my
dismay it turned out I was in the right place.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Sorry, I forgot to answer your questions.

All section breaks (including the new one) are as the one shown above,
wdSectionBreakNextPage.
The cursor is on section 7 (page 7). I thought this was the problem
so I added a few 'Selection.TypeParagraph' lines to get a visual and
to my dismay it turned out I was in the right place.

OK, from the code you posted, I see that it would be useful to rewrite it to
remove the Slection object which causes all kinds of problems, especially
since you seem to be opening the header pane when it is not necessary.

Can you clarify what it is the code is supposed to be doing?

From this thread I think you want to add a section at the end of the
document that already contains 6 sections and that have all their
headers/footers unlinked from previous sections.
The document seems to already be in different odd/even mode, so it is not
necessary to code for that...

If the above is true, try this code:

'____________
Sub AddSection()

Dim SecCount As Long
Dim DocRange As Range

SecCount = ActiveDocument.Sections.Count
Set DocRange = ActiveDocument.Range

With DocRange
.Collapse wdCollapseEnd
.InsertBreak wdSectionBreakNextPage
End With

SecCount = SecCount + 1

With ActiveDocument.Sections(SecCount)
With .PageSetup
.TopMargin = InchesToPoints(1.45)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.HeaderDistance = InchesToPoints(1)
.FooterDistance = InchesToPoints(1)
.DifferentFirstPageHeaderFooter = True
End With
.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
.Footers(wdHeaderFooterFirstPage).LinkToPrevious = False
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With

End Sub
'____________

This does not add extra pages to my document.

____________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

ccrites

Still the same result.

The problem is that I format the footers (on section 7 and beyond) so
that even page #'s are on the left and odds on the right, by actually
going in to the footers and saying 'paragraphalignleft' and vice versa.
I set up the first page with a user-defined 'FirstPageStyle' (always
odd page) and then the next page with 'EvenPageStyle' and then the next
page with 'OddPageStyle' and then backspace out of those to get back to
the first page. If the OddAndEven setting is not true then when I go
off the first page and into the second page (even) the formatting is
gone and the page # is on the same side (right) as the page above.

If I do set the OddAndEven setting, those styles that I set up persist
but like i said, the 4 blank pages are added to sections 1, 2, 5 & 6.

After I run this macro, if I run another one that sets the setting to
False, the blank pages disappear and the formatting of the preceding
page #'s disappear.

If you say that OddAndEvenPagesHeaderFooter affects the whole document,
then really is there any solution? Do I need to set those earlier
sections to a different setting for OddAndEven, because sections 3 and
4 don't get extra pages so something is different, which I'll try to
find.
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Still the same result.

I am not sure what to say at this point because the code I posted does not
create the problem you seem to have on my machine. So, I think this means
that there is something wrong with your document set up.
The problem is that I format the footers (on section 7 and beyond) so
that even page #'s are on the left and odds on the right, by actually
going in to the footers and saying 'paragraphalignleft' and vice

Do not go into the footer. Use the Range object.
versa. I set up the first page with a user-defined 'FirstPageStyle'
(always odd page) and then the next page with 'EvenPageStyle' and

You mean you have a "Next page odd" section break, but no "different
odd/even" section setting?
You know you are going to add a section that requires different odd and even
headers/footers. So, make sure that you set this up for the existing
sections before running the macro. This way, the added section will
automatically have this setting as it is document wide (no need to code for
that, as in my previous post example).
then the next page with 'OddPageStyle' and then backspace out of

I would recommend not using the Selection object to add and then remove
stuff.
those to get back to the first page. If the OddAndEven setting is
not true then when I go off the first page and into the second page
(even) the formatting is gone and the page # is on the same side
(right) as the page above.

Yes, because you do not seem to have different even/odd for your existing
sections.
If I do set the OddAndEven setting, those styles that I set up persist
but like i said, the 4 blank pages are added to sections 1, 2, 5 & 6.

After I run this macro, if I run another one that sets the setting to
False, the blank pages disappear and the formatting of the preceding
page #'s disappear.

If you say that OddAndEvenPagesHeaderFooter affects the whole
document, then really is there any solution? Do I need to set those

Yes, I have done tbhis many times.
earlier sections to a different setting for OddAndEven, because
sections 3 and 4 don't get extra pages so something is different,
which I'll try to find.

Set up the whole document with different odd/even headers/footers, you can
keep "Same as previous" in this case for all footers. Just set up the first
section. You can add a temporary even page to set up the footers. Then
delete it. Word will remember those settings and later sections that have an
even footer will pick it up from the first section, even if this first
section does not actually have an even page.

Then your code can be as simple as the one I posted previously.

If you try all this and still run into the same problem, send me your
document after you have tried using my code (or something along the same
lines) and I will have a look.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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