Odd Numbered Chapter Pages 
Author Message
 Odd Numbered Chapter Pages

I am writing a VBA macro to produce a report.

I want to start each chapter on an odd-numbered page.

From within the macro, how can I arrange to insert a blank page if required ?  

It also needs to be able to cope with repagination, so that the extra blank page
will be removed if subsequent updates to the document result in the odd pages
becoming even, and vice-versa.

I can't use an Odd-page Section Break because I need to stay in the same Section
for several paragraphs in order to retain the Headers and Footers - in them I am
displaying the Part Name as well as the Chapter name, and there are several
Chapters in each part.

Thanks

Dave

Thanks

Dave



Mon, 01 Dec 2003 20:15:47 GMT  
 Odd Numbered Chapter Pages

Dave,

It's doable in code (see below), but I wonder if you couldn't just
create a template containing the necessary field codes (which are
a bit complex but still easy compared the VBA) at the top of each
chapter, and pour your text into the space between those codes.

Anyway, here's one way to do it with VBA.  This would go at the
very top of the page that must be odd, that is, *after* a single
manual page break.  (I've found this slightly safer than placing
it at the end of the previous chapter because it doesn't seem to
get accidentally trashed quite as often.

Sub ForceOddPageViaCode()
ActiveDocument.ActiveWindow.ActivePane.View.ShowFieldCodes = True
With Selection
   .Fields.Add Range:=Selection.Range, Type:=wdFieldIf, _
       Text:=" = 0 " & Chr(34) & Chr(34) & " " & _
       Chr(34) & Chr(12) & Chr(34), PreserveFormatting:=False
   .MoveLeft Unit:=wdCharacter, Count:=13
   .InsertFormula Formula:="=MOD(,2)"
   .MoveRight Unit:=wdCharacter, Count:=7
   .Fields.Add Range:=Selection.Range, Type:=wdFieldPage, _
       PreserveFormatting:=False
End With
End Sub

Note that this puts a page break (Chr(12)) *inside* the field braces,
meaning it'll be sort of hard to look at when codes are on.


------ WWW: http://www.speakeasy.org/~mtangard ----------------------
------------- "Life is nothing if you aren't obsessed." --John Waters
---------------------------------------------------------------------

Quote:

> I am writing a VBA macro to produce a report.

> I want to start each chapter on an odd-numbered page.

> From within the macro, how can I arrange to insert a blank page if required ?

> It also needs to be able to cope with repagination, so that the extra blank page
> will be removed if subsequent updates to the document result in the odd pages
> becoming even, and vice-versa.

> I can't use an Odd-page Section Break because I need to stay in the same Section
> for several paragraphs in order to retain the Headers and Footers - in them I am
> displaying the Part Name as well as the Chapter name, and there are several
> Chapters in each part.

> Thanks

> Dave

> Thanks

> Dave



Mon, 01 Dec 2003 22:44:52 GMT  
 Odd Numbered Chapter Pages
Hi Mark - thanks for your quick response to my query regarding forcing new
Chapters on an odd-numbered page.

I've used your code, but I find I'm getting unpredictable results - parts of the
coding you gave me gets inserted into text which I am subsequently inserting
using TypeText (such as the Chapter Title), or my TypeText text is appearing in
the middle of the field coding, and any insert paragraph or insert page breaks I
use also seem to mess up the document.

My code even seems to be executing out of sequence - I have page breaks being
inserted after my typing even though I have given the commands at the beginning
of the module.  

This applies whether I'm running your code inline inside my module, or calling it
as a separate subroutine from inside my module.

Is there an obvious reason for this that I'm missing?

ALSO - you said it would be easier to use field codes in the template - I would
like to do that, but my report has several Parts, and each Part has several
Chapters.   When I start a new Section for a new Chapter, it resets the Headers
and Footers and so I lose the Part title which I had inserted with a StyleRef
field.   Is there a way round this?

Hope you can help - thanks.

Dave

Quote:
-----Original Message-----

Dave,

It's doable in code (see below), but I wonder if you couldn't just
create a template containing the necessary field codes (which are
a bit complex but still easy compared the VBA) at the top of each
chapter, and pour your text into the space between those codes.

Anyway, here's one way to do it with VBA.  This would go at the
very top of the page that must be odd, that is, *after* a single
manual page break.  (I've found this slightly safer than placing
it at the end of the previous chapter because it doesn't seem to
get accidentally trashed quite as often.

Sub ForceOddPageViaCode()
ActiveDocument.ActiveWindow.ActivePane.View.ShowFieldCodes = True
With Selection
   .Fields.Add Range:=Selection.Range, Type:=wdFieldIf, _
       Text:=" = 0 " & Chr(34) & Chr(34) & " " & _
       Chr(34) & Chr(12) & Chr(34), PreserveFormatting:=False
   .MoveLeft Unit:=wdCharacter, Count:=13
   .InsertFormula Formula:="=MOD(,2)"
   .MoveRight Unit:=wdCharacter, Count:=7
   .Fields.Add Range:=Selection.Range, Type:=wdFieldPage, _
       PreserveFormatting:=False
End With
End Sub

Note that this puts a page break (Chr(12)) *inside* the field braces,
meaning it'll be sort of hard to look at when codes are on.


------ WWW: http://www.speakeasy.org/~mtangard ----------------------
------------- "Life is nothing if you aren't obsessed." --John Waters
---------------------------------------------------------------------


> I am writing a VBA macro to produce a report.

> I want to start each chapter on an odd-numbered page.

> From within the macro, how can I arrange to insert a blank page if required ?

> It also needs to be able to cope with repagination, so that the extra blank page
> will be removed if subsequent updates to the document result in the odd pages
> becoming even, and vice-versa.

> I can't use an Odd-page Section Break because I need to stay in the same Section
> for several paragraphs in order to retain the Headers and Footers - in them I am
> displaying the Part Name as well as the Chapter name, and there are several
> Chapters in each part.

> Thanks

> Dave

> Thanks

> Dave
.



Tue, 02 Dec 2003 04:30:42 GMT  
 Odd Numbered Chapter Pages

Hi Mark - with regard to my earlier query regarding forcing new Chapters on an
odd-numbered page, I didn't get the insert If...MOD field working properly.

But I worked on your suggestion of using sections in the template and I have
finally the odd-page issue working fine.

Thanks again for your help.

Regards

Dave



Tue, 02 Dec 2003 08:49:44 GMT  
 Odd Numbered Chapter Pages

Quote:
> Hi Mark - with regard to my earlier query regarding forcing new
> Chapters on an odd-numbered page, I didn't get the insert If...MOD
> field working properly.

It's definitely tricky and I'm not surprised.  Inserting just *one*
field with code is nonsimple, and inserting *nested* fields can be
a real comedy.  Also, I was testing it on an empty line.  If you had
other things nearby, it's very possible they "got in the way" and
caused the lines that move the cursor to mislocate it.

Quote:
> But I worked on your suggestion of using sections in the template
> and I have finally the odd-page issue working fine.

Good.  I could sort of tell it was mainly a matter of finding a "safe"
spot for those things so they couldn't be inadvertently erased.

Mark



Tue, 02 Dec 2003 14:13:19 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Generating Page Numbers for Chapters

2. Chapter Number/Title Associated with Search Question

3. even or a odd number help please

4. HELP -- Determining whether a number is even or odd

5. Odd Error Numbers

6. Odd / Even Pages from a report?

7. Odd page identifier

8. Creating document out of db, altering table widths odd/even pages

9. inserting an odd page

10. Particular Style Always on Odd Page

11. Reports with different even and odd pages?

12. Printing Odd - Even Pages in DataReport

 

 
Powered by phpBB® Forum Software