PDA

View Full Version : Print VBA cancel command not working



Tony
02-07-2013, 03:36 AM
Hi all,

I use the following code to print a worksheet.


Private Sub CommandButton3_Click()
If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("INPUT WV").PrintOut
End Sub

I can cancel the dialogprintersetup without any error. But when i try to cancel e.g. the pdf save as dialog when i choose a pdf printer it gives me a runtime error and point to the Sheets("INPUT WV").PrintOut. When i save the pdf everything is just fine.

Regards,

Excel Fox
02-07-2013, 07:09 PM
That's because you are not going ahead with the print, and cancelling it after you select the printer. I'd just put in an


On Error Resume Next statement before that line