Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to print excel file

Status
Not open for further replies.

kerbaule

IS-IT--Management
Dec 29, 2003
24
FR
Bonjour,

I need to print excel files in batch or schedule job using a script or vbscript ?

Cab somebdy help me ? I don't know vbscript ...

many thanks

Regards

Elisabeth


 
A starting point (in VBS):
strDir = "/path/to/directory"
arrFile = Array("FileName1.xls","FileName2.xls","FileName3.xls")
Set objXL = CreateObject("Excel.Application")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strDir)
For Each strFile In arrFile
Set objFolderItem = objFolder.ParseName(strFile)
For Each V in objFolderItem.Verbs
If InStr(1,V,"Print",1) Or InStr(1,V,"Imprimer",1) Then
v.DoIt: Exit For
End If
Next
Next
objXL.Quit
WScript.Quit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
many thanks for your script ...

it's work, but I need also to send to this script parameters : folder and filename ..

sorry or this late details ...

Regards

Elisabeth

 
here is my script

Option Explicit
Dim objArgs, strDir, arrFile, arrFile1, objXL, objShell, objFolder , strFile, objFolderItem, V

'Make sure two command line arguements were supplied
Set objArgs = WScript.Arguments
If objArgs.Count < 2 Then
WScript.Echo "Wrong number of arguments! You need to supply the directory and the filename!"
WScript.Quit
End If


strDir = objArgs(0) 'Get the first command-line parameter
arrFile1 = objArgs(1) 'Get the second command-line parameter
'strDir = "/path/to/directory"
arrFile = Array(arrFile1)
Set objXL = CreateObject("Excel.Application")
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strDir)
For Each strFile In arrFile
Set objFolderItem = objFolder.ParseName(strFile)
For Each V in objFolderItem.Verbs
If InStr(1,V,"Print",1) Or InStr(1,V,"Imprimer",1) Then
v.DoIt: Exit For
End If
Next
Next
objXL.Quit
WScript.Quit


But I have an error message on objXL.QUIT :
Error :Call was rejected by callee
code :80010001
Source: null

Can somebody help
MAny thanks

Elisabeth


 
Hello kerbaule!

I think PHV was the victim of copy and paste (happens to all of us). You can simply remove the objXL declaration, the set objXL statement, and the objXL.quit statement.

The reason for the error is that it is trying to close excel when it isn't open to begin with. The set objXL statement simply creates a reference to the excel object, but does not actually open excel. However, since you don't use the objXL variable anywhere, you don't need it. Removing objXL will solve your problem.

It is also good practice to destroy all object references at the end of your script. This would include...
Code:
Set objFolder = Nothing
Set objShell = Nothing
Good luck!

He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Replace this:
Next
objXL.Quit
WScript.Quit
By something like this:
Next
Dim try
On Error Resume Next
For try = 1 To 5
objXL.Quit
If Err.Number = 0 Then Exit For
Err.Clear
WScript.Sleep 2000
Next
If Err.Number <> 0 Then objXL.Visible = True
WScript.Quit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello PHV ,

It's working correctly. Many thanks for your help

Regards

E.kerbaul


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top