Excel to PDF

Following my Word to PDF convertor script, here is the Excel version.

Prerequisites
MS Excel 2007
Office 2007 Save As PDF Plugin

Same rules apply. Copy and paste the code into notepad and save onto the desktop as ExceltoPdf.vbs.

<code>'Excel to PDF
'By John Reid
'(c) 2007 bloggingIT - http://ccgi.maxpower.plus.com/wp

'Feel free to use, modify, and redistribute - just leave the credits intact

'Quick Export to PDF
Const xlTypePDF = 0

if  Wscript.Arguments.Count &gt; 0 Then

 'Fire up MS Excel 2007
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objExcel = CreateObject("Excel.Application")
 
 'Enumerate the passed in file names
 For i = 0 to wscript.arguments.count - 1
  Set objFile = objFSO.GetFile(WScript.Arguments(i))
  Set objDoc = objExcel.Workbooks.Open(WScript.Arguments(i),,TRUE)
  dirPath = objFSO.GetParentFolderName(objFile)
  fileBaseName = objFSO.GetBaseName(objFile)
  'Export to PDF using preferred settings
  pdf = objExcel.ActiveWorkbook.ExportAsFixedFormat (xlTypePDF,dirPath & "\" & fileBaseName & ".pdf")
  objExcel.ActiveWorkbook.Close(False)
 Next
 'Quit MS Excel
 objExcel.Quit
Else
 msgbox("You must select a file to convert")
End If</code>

Once saved, just select and drag any Excel document onto the script, and a PDF will be created in the same directory.

Yey!