Gingertrees
11-11-2009, 09:45 AM
Hi all,
For any sheets in my workbook over 1 page long, I have "print this page" command buttons. The code looks like this:
Private Sub CommandButton11_Click()
'print Greivance pg
'initial range tells it to just print this page; after printout resets to entire
'workbook (pgs 1-21)
Sheet11.PageSetup.PrintArea = "$A$704:$AM$757"
Application.Dialogs(xlDialogPrinterSetup).Show
'lets user select printer; needed as users use different workstations often
Sheet11.PrintOut
Sheet11.PageSetup.PrintArea = "$A$1:$AM$1114"
End Sub
I added the dialogs because if the user selected "cancel" for page setup (like if it tried to print to file or XPS doc.writer), I get a runtime error 1004 "Application-defined or object-defined error". Now if they hit cancel it still tries to print, and can still get to the Runtime error if they try hard enough. I feel like this could be fixed with an If OK then sheet11.printout
If Cancel then Sheet11.PageSetup.PrintArea = "$A$1:$AM$1114"
Exit Sub
End Sub
but the if thens just do nothing. I realize I need some Errorhandling but I'm not skilled at that. Help?
For any sheets in my workbook over 1 page long, I have "print this page" command buttons. The code looks like this:
Private Sub CommandButton11_Click()
'print Greivance pg
'initial range tells it to just print this page; after printout resets to entire
'workbook (pgs 1-21)
Sheet11.PageSetup.PrintArea = "$A$704:$AM$757"
Application.Dialogs(xlDialogPrinterSetup).Show
'lets user select printer; needed as users use different workstations often
Sheet11.PrintOut
Sheet11.PageSetup.PrintArea = "$A$1:$AM$1114"
End Sub
I added the dialogs because if the user selected "cancel" for page setup (like if it tried to print to file or XPS doc.writer), I get a runtime error 1004 "Application-defined or object-defined error". Now if they hit cancel it still tries to print, and can still get to the Runtime error if they try hard enough. I feel like this could be fixed with an If OK then sheet11.printout
If Cancel then Sheet11.PageSetup.PrintArea = "$A$1:$AM$1114"
Exit Sub
End Sub
but the if thens just do nothing. I realize I need some Errorhandling but I'm not skilled at that. Help?