Print page one of sheet only

Y

ypukpete

I am using the code, Application.Dialogs(xlDialogPrint).Show (so the user can
select their printer) and I need to disable the Print Range in the dialog box
so that other pages cant be printed.
Is there code I can use to only print page 1 of the sheet. I have tried code
that works but if you click cancel in the dialog box it goes ahead and prints
it anyway. I hope this makes sense to one of the experts. Thanks for any help
 
O

OssieMac

The following only allows the user to select the printer and printer setup.
Does not allow selection of pages to print. Then the second line to actually
print.

Application.Dialogs(xlDialogPrinterSetup).Show

ActiveWindow.SelectedSheets.PrintOut from:=1, to:=1, _
copies:=1, collate:=True

Note that the space and underscore at the end of a line is a line break in
an otherwise single line of code.
 
Y

ypukpete

Thanks OssieMac. That is similar to the code I am using which works OK, but
if the user clicks on the cancel button in the print dialog box, it does not
cancel the printing. Is there away to correct this?
 
O

OssieMac

Hi again,

The following example should point you in the right direction.

Sub test()

Dim userResponse As Boolean

userResponse = Application.Dialogs(xlDialogPrinterSetup).Show

If userResponse = False Then
MsgBox "User clicked Cancel"
'Insert your code here in lieu of msgbox to handle the cancel
Else
'Remove msgbox and uncomment the printout line
MsgBox "User clicked OK"
'ActiveWindow.SelectedSheets.PrintOut from:=1, to:=1, _
copies:=1, collate:=True
End If

End Sub
 
Y

ypukpete

Thanks OssieMac it is what I want, I can also use this application for other
problems as well. Thanks for your time helping me.
 

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