Automatic page break

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Automatic page break

Post by Sundog »

I'm running Word 2007, and am trying to implement John McGhie's automatic page break approach, from http://www.word.mvps.org/FAQs/TblsFldsF ... ndChap.htm. Here is my code, exactly following his suggestion,{ IF{ =MOD({ PAGE \* Arabic },2)}= 0 " " "[page break]This page is intentionally blank." } :

Code: Select all

{^IF{^=MOD({^PAGE^\*^Arabic^},2)}=^0^"^"^"[Ctrl+Enter]This page is intentionally blank."^}
where { } were entered with Ctrl+F9, ^ denotes a space, and [Ctrl+Enter] denotes a hard page break.

He indicates he puts it at the end of a chapter, p. 5 in my test. I can't seem to get it to work, even in a sample document. After I Select All and hit F9 and OK the Update page numbers only, or Update entire table, the first part of the code remains, with a Page Break between the ^" and This, with This page is intentionally blank."^} on the following page, p.6, followed by the page text that was on page 6. The page number of that page is still 6.

I've set my Macro Settings to Enable all, and checked the Trust access to VBA. Any ideas?
Sundog

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

The main page for this group warns that some or all code may not be suitable for younger audiences using Word 2007...

I've posted this question to them, and will post their reply.
Sundog

User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic page break

Post by HansV »

There should be a page break after the field code too, or the first paragraph of text after the field should have the Page Break Before check box ticked.
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Hans, won't inserting manual page breaks obviate the automatic nature of what this field was designed to do?
Sundog

User avatar
StuartR
Administrator
Posts: 12628
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Automatic page break

Post by StuartR »

Sundog wrote:Hans, won't inserting manual page breaks obviate the automatic nature of what this field was designed to do?
Not if the manual page break is embedded in an IF field.
StuartR


User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic page break

Post by HansV »

The "fixed" manual page break ensures that the new chapter begins on a new page (which could be an odd or even page). The page break inside the field ensures that the chapter begins on an odd-numbered page.
Alternatively, you can insert an odd-page section break before a new chapter instead of the two page breaks.
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Stuart, Hans, where would you put the additional manual page break in the code I described (there already is a page break in the IF field, just prior to the This page text)?

I'm thinking that the way I normally see an IF expression outside of field code brackets is: =IF(something to evaluate, do this if false, do this if true). Note the comma separators. That implies to me that maybe there ought to be a couple of commas added to McGhie's expression, like this:{ IF{ =MOD({ PAGE \* Arabic },2)}= 0, " ", "[page break]This page is intentionally blank." }.

I'll try that and post the results.
Sundog

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Nope, commas didn't help.
Sundog

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Neither did this: { IF(=MOD(PAGE \* Arabic),2)=0," ","[page break]This page is intentionally blank.") }
Sundog

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Neither did this: { IF(=MOD(PAGE \* Arabic),2)=0," ","This page is intentionally blank.[page break]") }
Sundog

User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic page break

Post by HansV »

Take a look at the attached sample document. Make sure that field codes are *not* displayed, but do display paragraph breaks, page breaks etc.

The line 'This page is intentionally blank' should be visible on a page of its own (page 4). The second chapter begins on page 5.

Now remove enough text from the first chapter to make that line move back one page, to page 3. The second chapter now begins on page 4.

Press Ctrl+A then F9. You should see the line 'This page is intentionally blank' disappear. The second chapter should begin on page 3.
PageBreaks.docx
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Yes!

So you added a space after IF, added a space after 2), took out a space between the first two quote " marks, and took out a space before the page break. That works in your magic document. If I try to replicate (not copy) your code further down , bottom of p.6 in the attached, it doesn't work.

What did I do wrong? Or is it my copy of Word 2007 that is at fault?
You do not have the required permissions to view the files attached to this post.
Sundog

User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic page break

Post by HansV »

It does work! You only forgot to select all (or the field) and to press F9...
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

Blast. :blowup: I was going back and forth between Alt+F9s and must not have done the deed after the last switch.

So John's Word 2003 code was incorrect? Or does Word 2007 do things slightly differently?
Sundog

User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic page break

Post by HansV »

I think the only essential point is that there is a space between = and 0, the rest doesn't really matter, so John McGhie's code is ok.
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

It appears that I need to Ctrl+A and F9 twice (at least) after I've looked at fields with Alt+F9.

That probably was why I couldn't get it to work. I tried John's code again and it does work in Word 2007, AS LOOONNNGGG AS VIE HIT THE CRTL+A AND F9 TWICED.
Sundog

User avatar
HansV
Administrator
Posts: 78621
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automatic page break

Post by HansV »

It may be that Word has to recalculate the page numbers first and then the result of IF based on the recalculated page number.
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: Automatic page break

Post by Sundog »

I think you've got it. With multiple autoBlankettyBlanks (the technical term for the code) scattered throughout the document, it seems to take several Ctrl+A and F9s.
Sundog