In some Excel (2003) workbooks, when I attempt to print multiple sheets, Excel treats the sheets as separate print jobs. This fubars the excel automation app I've been writing since it causes Adobe PDF Printer to stop and ask the user for the second file name.
It looks like it might be something to do with the assigned print area of each page though clearing (or even resetting) the print area does not make a difference.
How can I force Excel to print all selected sheets as a single print job? (I'm using the virtual Adobe PDF Printer)
Barring that, how can I detect, in advance of printing, when Excel will treat one or more of the selected tabs as a separate print job?
I'm automating Excel 2003 with C3/.net3.5 and printing using the Adobe PDF Printer installed by Acrobat 7 Pro.
Use PrintOutEx():
foreach (Excel.Worksheet ws in wb.Worksheets)
{
Excel.PageSetup ps = (Excel.PageSetup)ws.PageSetup;
ws.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape;
ws.PageSetup.Order = Excel.XlOrder.xlDownThenOver;
ws.PageSetup.FitToPagesWide = 1;
ws.PageSetup.FitToPagesTall = 50;
ws.PageSetup.Zoom = false;
}
wb.Worksheets.PrintOutEx();
According to Microsoft support, Excel may decide to spool multiple print jobs for a single print request. A single Excel print job covers one or more print areas. If you iterate over the print areas and invoke print each and every print area, you regain some control over the output.
Once all the jobs have completed, you can proceed to bind all of the pieces into a single PDF file. Some time ago I used this approach (with Win2PDF driver) to convert Excel to PDF on site.