How can I convert Excel documents (files) to PDF in an automated fashion? I am trying to adapt the solution found here to Excel. So far I have this:
var fso
You're clobbering objExcel on line 15:
var objExcel = objExcel.Workbooks.Open(docPath);
Those lines of code need to use a different variable, e.g.:
var objWorkbook = objExcel.Workbooks.Open(docPath);
var wdFormatPdf = 57;
objWorkbook.SaveAs(pdfPath, wdFormatPdf);
objWorkbook.Close();
Try to use .ExportAsFixedFormat
property instead of .SaveAs
. First one is suitable for creating PDF files in Excel but not SaveAs which doesn't support PDF format.
I guess you would need something like this:
objExcel.ExportAsFixedFormat(0, pdfPath)