Friday, October 1, 2010

VBScript: How to print a document after a delay

Have you ever worked in a crowded office with public and shared printers, but needed to print something personal or confidential? If you have then you've know that moment of gut-clenching, cold-sweating nausea that accompanies the old "hit print and run like hell to the printer" routine. I've had to do it in the past, and I've hated it.

So, here's a quick little script that can make life a little easier. When you run the script it will prompt you for a number of seconds to wait and the path to a Word Document (.doc) that you want to print. Just enter it in the format of "Seconds, FilePath" such as 30, C:/Temp/Test1.doc and hit enter. The script will then wait the number of seconds specified, open Word and print your document to your default printer, giving you plenty of time to walk over and stake your claim to privacy.


'-----------------------------------------------------------------
Input1 = InputBox("Seconds, FilePath",, "30, C:/Temp/Test1.doc")
findComma = Instr(Input1, ", ")-1
Seconds = left(Input1, findComma)
FilePath = right(Input1, Len(Input1)-(findComma +2))
call delayPrint(Seconds, FilePath)

function delayPrint(Seconds, FilePath)
WScript.Sleep Seconds * 1000
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(FilePath)
objDoc.PrintOut()
objWord.Quit
end function
'-----------------------------------------------------------------


Enjoy,

No comments: