cancel a print that is called in a macro

Loreng

New Member
Joined
Sep 23, 2004
Messages
31
I have a macro that prints 2 tabs in a workbook, the first is a summary printed in landscape, and the second tab is 15 pages of detail, printed in portrait.

I found some code in the archives that helped me pull up the print dialog box, which works perfectly for allowing the user to choose their printer, and other options.....except when the user cancels the print, it still prints the detail tab!

Is there an easy way for the macro to quit if the user cancels the first print job?.....i could call up the printer dialog box twice, but that would be confusing.

Here's my VBA code:

Sub print_book()'
Sheets("Summary").Select
Application.Dialogs.Item(xlDialogPrint).Show
Sheets("Details").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub


Thanks for your help!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Juan Pablo,

:pray: :pray: :pray:

thanks for the very fast response.......i replaced the line with your code...it's perfect!

Sub print_book()'
Sheets("Summary").Select
If Not Application.Dialogs.Item(xlDialogPrint).Show Then Exit Sub
Sheets("Details").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,603
Messages
6,125,776
Members
449,259
Latest member
rehanahmadawan

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