' Script to print multiple excel files
Dim DocToPrint, oExcel, oDoc
Welcome_MsgBox_Message = "This script will print all Excel files in the folder this" & _
" script was run from."
Welcome_MsgBox_Title = "File Printer"
Call Welcome()
' Get the full path and filename of the script file
scriptfile = WScript.ScriptFullName
' Get the path to the script file
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(scriptfile)
scriptpath = f.ParentFolder
Set f = Nothing
Set fl = fso.GetFolder(scriptpath)
Set fc = fl.Files
' Create the excel object
Set oExcel = CreateObject("Excel.Application")
For Each f in fc
DocToPrint = scriptpath & "\" & f.name
If Right(DocToPrint,3) = "xls" Then
Set oExcelActiveDoc = oExcel.Workbooks.Open("" & DocToPrint)
oExcelActiveDoc.PrintOut
oExcel.Workbooks.Close
End If
Next
Set oExcel = Nothing
WScript.Quit(0)
' ********************************************************
' *
' * Welcome
' *
' ********************************************************
Sub Welcome()
Dim intDoIt
intDoIt = MsgBox(Welcome_MsgBox_Message, _
vbOKCancel + vbInformation, _
Welcome_MsgBox_Title )
If intDoIt = vbCancel Then
WScript.Quit
End If
End Sub