Number of pages

F

fernando

Hello,

I need to find out how many pages does a sheet contain
(can be 1 or 2 pages only), before sending the following
line: sheet.PrintPreview, ex

PageNum = sheet.Number_Of_Pages_To_Be_Printed
if PageNum = 1 then
sheet.PrintPreview
else
alert user
end if

This will print a 1 page list, if the number of items
exceeds the 1st page, the printing has to be cancelled

Thanks in advance!
 
W

William

Hi fernando

'Place in "ThisWorkbook" module
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
HowManyPages
End Sub


'Place in a "General" module
Sub HowManyPages()
Dim Cmd As String
Cmd = "GET.DOCUMENT(50,""" & ActiveSheet.Name & """)"
If Application.ExecuteExcel4Macro(Cmd) = 1 Then
Application.EnableEvents = False
ActiveSheet.PrintPreview
Application.EnableEvents = True
Else
MsgBox "Too many sheets"
End If
End Sub


--
XL2002
Regards

William

(e-mail address removed)

| Hello,
|
| I need to find out how many pages does a sheet contain
| (can be 1 or 2 pages only), before sending the following
| line: sheet.PrintPreview, ex
|
| PageNum = sheet.Number_Of_Pages_To_Be_Printed
| if PageNum = 1 then
| sheet.PrintPreview
| else
| alert user
| end if
|
| This will print a 1 page list, if the number of items
| exceeds the 1st page, the printing has to be cancelled
|
| Thanks in advance!
 
P

Pierre Archambault

Try this:

If you want to make sure that each and every time you print, only 1 page is
used, go to: File | Page setup.

In the "Page" tab, choose to scale to 1 page in width and remove the 1 in
the height box.

Pierre
 

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