Drag and Drop Convert Word to PDF

Sometimes I find that it’s useful to save my Word documents as PDFs.

After playing around with the Save As PDF plugin for Office, I decided that it would be cool if I could write a script to convert a job lot of Word documents.

MS Word 2007
Save As PDF Office 2007 Plugin

Just copy and paste the code into Notepad and save the file as WordToPDF.vbs on your desktop.

<code>'Word to PDF
'By John Reid
'(c) 2007 bloggingIT - http://www.maxpower.plus.com
'Feel free to use, modify, and redistribute - just leave the credits intact
'Quick Export to PDF
Const wdExportAllDocument = 0
Const wdExportOptimizeForPrint = 0
Const wdExportDocumentContent = 0
Const wdExportFormatPDF = 17
Const wdExportCreateHeadingBookmarks = 1

if  Wscript.Arguments.Count > 0 Then
  'Fire up MS Word 2007
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objWord = CreateObject("Word.Application")

  'Enumerate the passed in file names
  For i = 0 to wscript.arguments.count - 1
  Set objFile = objFSO.GetFile(WScript.Arguments(i))
  Set objDoc = objWord.Documents.Open(WScript.Arguments(i),,TRUE)
  dirPath = objFSO.GetParentFolderName(objFile)
  fileBaseName = objFSO.GetBaseName(objFile)
  'Export to PDF using preferred settings
  pdf = objWord.ActiveDocument.ExportAsFixedFormat _
    (dirPath & "\" & fileBaseName & ".pdf", _
    wdExportFormatPDF, False, wdExportOptimizeForPrint, _
   wdExportAllDocument,,, _
   wdExportDocumentContent, _
   False, True, _
 'Quit MS Word
 msgbox("You must select a file to convert")
End If</code>

When you find a document that you wish to convert, just drag and drop the file onto the script.

Right, there’s an Excel version along shortly.