Excel automation: PDF export causes "Printer setup" popup
Asked Answered
M

3

7

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.

Print driver host for 32bit applications stopped working

and, shortly after, this one:

Printer setup

Printer setup Popup

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?

Mobcap answered 24/7, 2014 at 14:38 Comment(0)
M
11

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.

Mobcap answered 29/7, 2014 at 7:28 Comment(0)
G
0

I had a similar issue on my work laptop. The printer setup would pop-up when trying to execute ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="\directory\MyFile".

The network printer was set as default. So I navigated to the printer in windows explorer. This prompted me to enter my network password. When I re-ran the code it worked splendidly.(You can find the location of the printer in Windows 10 by typing 'printer' in the windows search bar. Click on Printers And Scanners, navigate to your network printer and then click on manage -> Select Hardware Properties. The location will be displayed next to the image of the printer. In my case the printers location was specified in its name).

In summary, ensure you have access to the default printer. A simple test is trying to print something with your default printer.

If you don't mind changing your default printer follow @F.P solution above.

Glycol answered 26/2, 2020 at 23:37 Comment(0)
O
0

Someties it,s needed to close your workbook and reopen it.

In my case, when I opened an excel file, it prompted me to click the "Enable Editing" button in the picture below:

enter image description here

When I clicked on it, the excel file wants to open again and Excel splash screen shown again and I closed it immediately. And then I was not to able to save as a PDF both with "Print" button and "VB" code.

Ostensory answered 5/1, 2022 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.