Hi script wizards,
I cobbled this together from info on the web but I don't know hardly anything about scripting - I'm a COBOL programmer! Works with word 2003/2007 (has been for some time) but not in Word 2010. The background printing commands fail (e.g. objWord.Options.PrintBackground = False). It works without them but then word is not invisible. I'd like one script that works in all versions. Help!
My script...
'*** This script converts all of the rtf files in the '*** current folder to PDF files for use with adBooker '*** email invoicing. Microsoft Word and PDFCreator '*** must already be installed on the same computer.
'*** Developed by Linden Rowland, October 2009. '*** Generated automatically by adBooker v2.08.
Set objFSO = CreateObject("Scripting.FileSystemObject")
If False = objFSO.FileExists("RGL7089_email_merge_data.csv") Then MSGBOX "Merge files missing! If you are " + _ "running from a zip folder, you need " + _ "to extract all of the files first " + _ "and run from there. Click OK to exit. " Wscript.Quit End If
If objFSO.FolderExists("C:EMAIL_INVOICE_MERGE") Then MSGBOX "About to empty folder, C:EMAIL_INVOICE_MERGE. If you need any of the files, move them now BEFORE clicking OK." objFSO.DeleteFile("C:EMAIL_INVOICE_MERGE*.*") Else MSGBOX "Ooops! - you may have tried to run this program by mistake - it can only be run on the computer that will send the email invoices. Click OK to exit." Wscript.Quit End If
strFolderName = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName))) Set objFolder = objFSO.GetFolder(strFolderName)
Set objWord = CreateObject("Word.Application") objWord.Visible = False strActivePrinter = objWord.ActivePrinter objWord.ActivePrinter = "PDFCreator"
For Each objFile In objFolder.Files IF right(objFile,4) = ".rtf" THEN strFileName = strFolderName & objFile.Name Set objDoc = objWord.Documents.Open(strFileName) objWord.Options.PrintBackground = False objDoc.PrintOut() objWord.Options.PrintBackground = True objDoc.Close() End if Next
objWord.ActivePrinter = strActivePrinter objWord.Quit
Const OverwriteExisting = True objFSO.CopyFile "*_email_merge_data.csv" , "C:EMAIL_INVOICE_MERGE", OverwriteExisting
MSGBOX "Before you run Pegasus, please check the PDFs in folder, C:EMAIL_INVOICE_MERGE. There may be a short delay before all of the PDFs appear."
Free Guide: Managing storage for virtual environments
Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!
Discuss This Question: