I am developing an application for automatic Excel to PDF generation. Every now and then (and without any apparent cause, the following popup comes up while the program runs:
Print driver host for 32bit applications stopped working.
and, shortly after, this one:
Printer setup
What, if anything, do I need to do here? My application is not overly complex. The error always (100%) happens on this line:
_application.ActiveWorkbook.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF,
pdfTemplatePath, Excel.XlFixedFormatQuality.xlQualityStandard,
_, _, 1, pdfPrintAreaEnd);
where the variables in question are:
Excel := Microsoft.Office.Intertop.Excel
_application := Excel.Application
_ := System.Type.Missing
pdfPrintAreaEnd := int 6
The exception message is as follows:
System.Runtime.InteropServices.COMException (0x800A03EC):
Exception from HRESULT: 0x800A03EC
What is happening here? And, more importantly: Why is it only happening every one in a while?
You might have accidentally saved the spreadsheet on a per worksheet basis rather than per workbook. If that so, you may need to change it in normal mode view. To do this, follow this steps: Open Excel.
There is a possibility of some Add-in conflicting with this. To rule this out, start Excel in safe mode and then print to pdf. Hold CTRL key and click on Excel icon. Don't leave CTRL key, till it asks for the confirmation about safe mode.
Okay, so after some research into this matter, I encountered what I believe is one of the most confuzzling things about Excel automation I have encountered so far.
The error message is consistent with other cases of Excel usage that are both automated and not. The common denominator in all these cases is (buckle up!) that a network printer was set as default printer.
That's right - having a network printer as default, even when you print using a completely different printer or no printer at all (as in the case of exporting to PDF, which is not the same as printing to e.g. Adobe PDF Printer, right?) it will cause this error to sometimes on some machines pop up.
I changed the default printer to something internal, like Microsoft XPS Document Printer, tried again and I can now export hundreds and thousands of PDFs without a single occurrence of the error message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With