Print Excel to PDF via COM

I’m using PDFCreator to print from Excel to PDF. The problem is that the resulting PDF file cannot be opened by Adobe Reader. I get the following error:

Could not open xxxxxx.pdf because it is either not a supported file type or because the file has been damaged…

In LotusScript…

-Extract the attachment (only for .xls attachments) to a temp location

-Create an Excel object

-Open the file { xl.Workbooks.Open(“c:\TEMP\file.xls”) }

-Create my PDF object { set pdfjob = CreateObject(“PDFCreator.clsPDFCreator”)

-For lSheet = 1 to wkbk.Sheets.Count… (looping through all worksheets)

-Call wkbk.Sheets(lSheet).PrintOut(, , 1, False, “PDFCreator”,True,False,)

Code executes without error but as I stated earlier the resulting PDF cannot be opened… If I open an Excel file manually and print to PDFCreator I can successfully convert to PDF. I have Excel 2007 running on my laptop. Also, if I run the above code and print to a normal printer there are no issues.

Subject: Print Excel to PDF via COM

For anyone interested…

I was able to overcome my problem by installing the “Save as PDF and XPS” add-in to Excel and rather than use the PrintOut method I’m using:

ExportAsFixedFormat(Type, Filename, Quality, IncludeDocProperties, IgnorePrintAreas, From, To, OpenAfterPublish, FixedFormatExtClassPtr)

Works like a charm!