views:

773

answers:

1

I am trying to use Interop.Excell to save an Excel Workbook as a PDF file. I am using VS2008 and Office2007, and have downloaded and installed the SaveAsPDFandXPS.exe from Microsoft. This enabled me to save a Word document as a pdf using the following code: object frmt = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; wrd.ActiveDocument.SaveAs(ref dest, ref frmt, ref unknown, ref unknown,... Pretty cool excpet for the whole Interop thing.

Anyway, I have been unsucsessful in finding a parallel in Interop.Excell for the Word.WdSaveFormat.wdFormatPDF. The Workbook.SaveAs takes a Interop.Excel.XlFileFormat, but there is no option for a pdf format. Has anyone done this or has experience in this area?

+2  A: 

This question has been answered here:

What is the FileType number for PDF in Excel 2007 that is needed to save a file as PDF through the API?

You need to call the Workbook.ExportAsFixedFormat method:

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF 
    FileName:=“sales.pdf” 
    Quality:=xlQualityStandard 
    DisplayFileAfterPublish:=True

This method should be preferred over using SaveAs because it also allows specifying all PDF / XPS options.

Note: This method has been added to the Excel object model with Excel 2007 and requires the Save as PDF or XPS Add-in for 2007 Microsoft Office programs (or SP2) to be installed.

0xA3