odd page numbers

D

Drake

Hi - I am wanting to add a piece of code that will add a page break at the
end of the document if the last page is an odd numbered page. Therefore,
this would create an even-numbered pages document.

So far,
dim pagenumber as Integer
Set pagenumber = Selection.Information(wdActiveEndPageNumber)
if pagenumber = cint(3,5,7,9)

What am I doing wrong?
 
D

DA

Hi Drake

Try this:

Selection.EndKey Unit:=wdStory
If ActiveDocument.Range.Information
(wdActiveEndPageNumber) _
Mod 2 <> 0 Then _
Selection.InsertBreak Type:=wdPageBreak

Hope this helps,
Dennis
 
D

Drake

Thanks Jay - I had looked at that but wasn't sure how to do it and thought
VBA would be cleaner as I already have a script going.

Thanks Dennis - working good. However, it seems that this If....Then is
functioning different than other ones I have done as it isn't accepting an
End If. Also, I want to have it do a few other things, but it isn't working
correctly. Here is what I added:

Selection.EndKey Unit:=wdStory
Selection.Paste
pagenumber = Selection.Information(wdActiveEndPageNumber)
If pagenumber Mod 2 <> 0 Then _
Selection.InsertBreak Type:=wdPageBreak
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.ColorIndex = wdGray25
Selection.TypeText Text:="This Page Intentionally Blank"

It does everything fine if the last page is odd, but if it is even, I end up
with "This Page Intentionally...." which I don't want.

What am I missing?
 
D

Drake

My mistake - I think I was leaving a "_" in and mixing single and block If
syntax.

Working great!
 

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