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 = new ActiveXObject("Scripting.FileSystemObject");
var docPath = WScript.Arguments(0);
docPath = fso.GetAbsolutePathName(docPath);
var pdfPath = docPath.replace(/\.xls[^.]*$/, ".pdf");
var objExcel = null;
WScript.Echo("Saving '" + docPath + "' as '" + pdfPath + "'...");
objExcel = new ActiveXObject("Excel.Application");
objExcel.Visible = false;
var objExcel = objExcel.Workbooks.Open(docPath);
var wdFormatPdf = 17;
if (objExcel != null)
Saving 'somefile.xlsx' as 'somefile.pdf'...
..\SaveXLSXAsPDF.js(27, 9) (null): The object invoked has disconnected from its clients.
An erroneous PDF file is created, and it will not open in a reader. Perhaps format 17 isn't the best choice for Excel, I'm thinking. Does anyone have the correct information or know how to make this work?