Question : Worksheets.print/printpreview cancel abend

I am running Excel 2007 (the problem also occurs in Excel 2003) and I'm running into a problem with both the WorkSheets.PrintPreview method and the Print method too.  I am executing the following code (boiled down from what I actually have):

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Worksheets(Array("NCR Form", "Page 2")).PrintPreview (True)
    Worksheets("Sheet1").Select  'select this worksheet exclusively to deselect the other sheets
    Sheets("NCR Form").Select   'select this worksheet exclusively
    Cancel = True
End Sub

When the print preview displays, if I go to print the file Excel displays the standard print dialog box through which I can select a printer and set other print options.  If I click OK on Print dialog box everything is fine however if I click Cancel Excel blows up and abends.

I tried commenting out the CANCEL = TRUE statement.  That solved the problem of Excel blowing up, but then it prints out the active worksheet unconditionally no matter if I cancel the print of the two worksheets or if I go ahead and print them.  In other words if I do let the print of the 2 worksheets go ahead I get a correct print of the worksheets NCR Form & Page 2 and then ANOTHER print of the NCR Form worksheet (which is why I put the Cancel statement in there in the first place).

So what is going on with the cancelling of the print operation in the worksheets.print or worksheets.printpreview?  Is there anyway I can keep Excel from blowing up and abending if the user cancels out of the print dialog window?

Rich

Answer : Worksheets.print/printpreview cancel abend

http://msdn.microsoft.com/en-us/library/aa221648(v=office.11).aspx
http://www.officekb.com/Uwe/Forum.aspx/excel-prog/96731/need-to-access-the-xldialogprint-object-parameters             <<<read all replies to the post

xlDialogPrint parameters:
range_num, from, to, copies, draft, preview, print_what, color, feed, quality, y_resolution, selection, printer_text, print_to_file, collate

sample usage
to ensure that the print selection is Entire Workbook when displaying the built-in Print dialog
   Application.Dialogs(xlDialogPrint).Show arg12:=3
      
Random Solutions  
 
programming4us programming4us