print out question

Kavy

Well-known Member
Joined
Jun 25, 2007
Messages
607
Hello using a excel vb form if i have wsf.printout where wsf is a worksheet and the user clicks cancel when the printing screen comes up (the one that says printing page, # of # and it goes through all the pages) i get a error saying print out failed and the vb debugger pops up. How can I stop this error?

Thanks!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
You could use an error handling routine:

Code:
Sub blah()
'your code here....
On Error GoTo bypass_print
wsf.PrintOut
'rest of your code here
Exit Sub
bypass_print: MsgBox "Bypass invoked, printout failed, or was cancelled"
End Sub
 
Upvote 0
Sykes, another question... That makes it exit my sub if someone clicks cancel, anyway to get it to just skip the print command?
 
Upvote 0
Hi Kavy

Yes, copy and paste all of your code (AFTER the wsf.printout line) again, underneath the "bypass_print:" line, but there's no need to include my "Exit Sub" line right at the bottom.

This way, if the print goes OK, then the code just continues as normal to the "Exit Sub" line then stops.
If the user cancels the print, the code errors, goes to the "bypass_print:" line, tells the user that the print's failed, but then carries on as if nothing's happened.

Code:
Sub blah()
'your code here....
On Error GoTo bypass_print
wsf.PrintOut
'rest of your code here
Exit Sub
bypass_print: MsgBox "Bypass invoked, printout failed, or was cancelled"
'rest of your "normal" code here again, but only after the wsf.printout line
End Sub

Hope this works for you
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,635
Members
449,043
Latest member
farhansadik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top