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

Optional page in Word 2000 or later

Status
Not open for further replies.

xwb

Programmer
Jul 11, 2002
6,828
GB
We have a document policy where we need the last page to be on an even number. I can put in an Odd Page Section break before the last page but what I get is a blank page without the headers or footers.

What I'd like to do is to put in a blank page with the headers and footers and a bit of text ("intentionally blank") if the last page is odd so that it makes the last page even.

Any ideas on how this can be achieved? Macros are acceptable if that is the only way to do it.
 
I'd imagine you'd need a Macro for this, as you mentioned as a possibility. I'd try working one up to get started, and then ask questions along the way over in forum707.

--

"If to err is human, then I must be some kind of human!" -Me
 
Thanks for responding. Just wanted to know if I could do it without a macro - something automatic like keep with next. I've been using Word and Excel since the early 90s and still discovering new features that I never knew existed.

I only discovered hidden text last week. Went back as far as Word 2000 and it is there. If there is no conditional feature then it is not a problem, I can easily write a macro to get around it.

Now the big decision is whether I do it in VBScript or VBA. Suppose I'll have to toss a coin:)
 
kjv is correct. It will likely need some VBA, although it is not difficult. As such, any further questions regarding code should be posted to the VBA forum.

Here is something that may get you started though.
Code:
Sub MakeItEven()
Dim r As Range
Dim LastPageNum As Long

Set r = ActiveDocument.Range
LastPageNum = r _
      .Information(wdActiveEndAdjustedPageNumber)
If LastPageNum Mod 2 <> 0 Then
   ' doc ends with an odd number
   r.Collapse Direction:=wdCollapseEnd
   r.InsertBreak Type:=wdSectionBreakEvenPage
   With Selection
      .EndKey Unit:=wdStory
      .Style = "LastPage"
      .TypeText Text:="intentionally blank"
   End With
End If
End Sub
This determines if the last page is odd or even. If it is odd, it makes a section break and adds the "intentionally blank" text. The text uses a "LastPage" style. I simply did that as I always use Styles. So I made a LastPage style to format the text to what I wanted. Centered, 20 pt Arial, SpaceBefore 90 pts. It could of course whatever you want.

The code does NOT, repeat not, do anything with the headers. You stated: "What I'd like to do is to put in a blank page with the headers and footers"

I took you at your word. Previous headers and footers will be carried over. If you have anything different, then that would have to be dealt with.

This may, or may not, be the solution for your situation. You may simply - if it is an odd number ending - want to add another page. Thus making it an even ending. No Section break. Then put your "intentionally blank" text. I would still suggest using a Style though.

You should also consider deeper error trapping. Say you ran this, and it was appropriate. An odd ending, so the intentionally blank page is added. Now, suppose text is added to previous pages. This could potentially screw up the appropriateness of that last page, yes?

It may no longer BE appropriate.

In which case, proper error trapping would:

1. check if ending page is odd or even
2. check if last page already has an "intentionally blank" content.

and proceed from there, logically.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks for the script. I've modified it to put the blank page as the penultimate page. Yes, we have some strange standard that the back cover is for signing (not the front cover).

Another strangeness that I've added is updating page 1. For some strange reason, all other pages get the correct number of pages except page 1. This happens in 2003, XP and 2000 where the Page 1 of n somehow never seems to update correctly, possibly because I've set different first page. Anyway it works now so it is onwards and sideways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top