Converting Excel to PDF with VS2008 and Office2007

calendar_today Asked Mar 11, 2009
thumb_up 7 upvotes
history Updated April 16, 2026

Question posted 2009 · +4 upvotes

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?

Accepted answer +7 upvotes

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.

External references cited (3)

Excel VBA objects referenced (5)

Top excel Q&A (6)

+7 upvotes ranks this answer #122 out of 167 excel solutions on this site .