Option Explicit : Dim objWord, objDoc, wssh, objFS, objShell, objPath, objFolder, objItem
Set wssh = CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objPath = objFS.GetFolder("G:\Мой диск\Печать") 'Папка, из которой производится печать
Do
PrintDelInFolder objPath
WScript.Sleep 3000
Loop
Sub PrintDelInFolder(objFolder)
For Each objItem In objFolder.Files
If StrComp(objFS.GetExtensionName(objItem.Name), "xls", vbTextCompare) = 0 Then
With wssh
WScript.Sleep 1000
On Error Resume Next
dim f
f = Cstr(objItem.Path+".xls")
objFS.MoveFile objItem.Path, f
If err.number=0 then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute f, "vbHide", "", "print", 0
set objShell = nothing
err.Clear
Do
WScript.Sleep 9000
rem
objFS.DeleteFile f ,true
rem objFS.movefile f ,("C:\print_arhiv\")
rem
Loop While objFS.FileExists(f)
err.Clear
End If
On Error Goto 0
End With
End If
Next
End Sub
WScript.Quit 0
Option Explicit : Dim objWord, objDoc, wssh, objFS, objShell, objPath, objFolder, objItem
Set wssh = CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objPath = objFS.GetFolder("G:\Мой диск\Печать") 'Папка, из которой производится печать
Set objTempFolder = objFS.CreateFolder("G:\Мой диск\Temp") 'Временная папка для файлов перед печатью
Do
PrintDelInFolder objPath
WScript.Sleep 3000
Loop
Sub PrintDelInFolder(objFolder)
For Each objItem In objFolder.Files
If StrComp(objFS.GetExtensionName(objItem.Name), "xls", vbTextCompare) = 0 Then
With wssh
WScript.Sleep 1000
On Error Resume Next
dim f
f = Cstr(objTempFolder.Path & "" & objItem.Name)
objFS.MoveFile objItem.Path, f
If err.number=0 then
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute f, "vbHide", "", "print", 0
set objShell = nothing
err.Clear
Do
WScript.Sleep 9000
objFS.DeleteFile f ,true
Loop While objFS.FileExists(f)
err.Clear
End If
On Error Goto 0
End With
End If
Next
End Sub
WScript.Quit 0
Option Explicit
Dim oFSO, oDesk, oSINK, oWMI, FName, Pr
'——— Вводные ———————————————————————————————————
Const iPath = "G:\Мой диск\Печать", Ext = ".xls"
'———————————————————————————————————————————————
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oDesk = CreateObject("Shell.Application").NameSpace(0)
Set oSINK = WSH.CreateObject("WbemScripting.SWbemSink", "SINK_")
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
oWMI.ExecNotificationQueryAsync oSINK, "SELECT TargetInstance.PartComponent FROM __InstanceCreationEvent" &_
" WITHIN 2 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' and TargetInstance.GroupComponent=" &_
"'Win32_Directory.Name=""" & Replace(iPath, "\", "\\\\") & """'"
Do: WSH.Sleep 8^10 :Loop
Sub SINK_OnObjectReady(oEvent, x)
FName = Replace(Split(oEvent.TargetInstance.PartComponent, """")(1), "\\", "\")
If LCase(Right(FName, 4)) = Ext Then
oDesk.ParseName(FName).InvokeVerb "print"
For Each Pr in oWMI.ExecQuery("SELECT JobCountSinceLastReset FROM Win32_Printer WHERE Default='True'")
While Pr.JobCountSinceLastReset: WSH.Sleep 200: Wend
Next
oFSO.DeleteFile FName, 1
End If
End Sub