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
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.