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:
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)
- stackoverflow.com — What is the FileType number for PDF in Excel 2007…
- msdn.microsoft.com — Workbook.ExportAsFixedFormat
- microsoft.com — Save as PDF or XPS Add-in
Excel VBA objects referenced (5)
Interop.Excel— Using events with Excel objectsInterop.Excel— Using Excel worksheet functions in Visual BasicInterop.Word— Exporting a Range to a Table in a Word DocumentInterop.Word— Using events with the Application object (Word)Microsoft.Office— Controlling One Microsoft Office Application from Another
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
.