Sunday, April 1, 2007

Excel Files Printing Automation

On Error Resume Next

Dim LoadDelay, QuitDelay
'Time to wait in ms(millisecond, 1 second=1000ms)
LoadDelay = 1000
QuitDelay = 1000

If (WScript.Arguments.Count = 1) Then
ExcelFileName = WScript.Arguments.Item(0)
Else
ExcelFileName = InputBox("Please Enter the Excel File Name > ")
End If

Set objExcel = WScript.CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.Workbooks.Open(ExcelFileName)
WScript.Sleep LoadDelay

'Print to the default printer
'Print the first sheet, sheet index starts from 1
'Set ObjSheet = objExcel.ActiveWorkbook.WorkSheets(1)
'ObjSheet.PrintOut

'Print all sheets in the workbook
objExcel.ActiveWorkbook.PrintOut

WScript.Sleep QuitDelay

objExcel.ActiveWorkbook.Close(False)

objExcel.Quit

No comments:

Related Titles

 
visitors since March 26 2007
©2007