如何使用 VBS 在 Windows 8 上打印多个 html 文件
How to print multiple html files on Windows 8 with VBS
我有一个包含 1650 HTML 个文件的文件夹,由于地方当局的原因,这些文件也必须以纸质形式打印。
我尝试过使用经典的 ctrl+A(即使我尝试的是较小的数量),然后我在右键菜单中寻找 PRINT 标签,但没有。
如果我选择打印多个jpg或pdf文件,出现PRINT语音。
我该如何打印多个 html 文件?批处理文件? (我不知道怎么做)。
我也考虑过将 html 转换为 pdf,但使用 PDF Creator 和 PDF Architect 都没有成功。
你们有什么经验可以分享吗?
我写了一些代码,混合了 Tim 给出的代码和我在 Whosebug 上找到的代码,但没有成功。
这里是:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Users\mainUser\Desktop\ft"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
strFileName = objFile.Name
If objFSO.GetExtensionName(strFileName) = "html" Then
On Error Resume Next
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
Dim objExplorer
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate objFolder.Path +"\"+ objFile.Name
objExplorer.Visible = 1
Do while objExplorer.ReadyState <> 4
WScript.Sleep 1000 'milliseconds
Loop
oIExplorer.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End If
Next
它只是在 Internet Explorer 中打开一个 html。我以为它会打开所有文件,并且已经在 PRINT "mode" 中。
我想我错过了什么。
查看此线程以循环访问目录中的文件:How to do something to each file in a directory with a batch script
然后您可以使用本机 PRINT
命令,这样您的批处理文件就可以像这样简单:
for /f "delims=|" %%f in ('dir /b c:\') do PRINT %%f
根据以下评论:
啊。然后,您可能必须使 IE 自动化以打印页面。按照这些行使用 VBScript:
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
objStartFolder = "C:\Users\mainUser\Desktop\ft"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set objExplorer = CreateObject("InternetExplorer.Application")
Set oShell = CreateObject("Shell.Application")
For Each objFile In objFolder.Files
strFileName = objFile.Name
If objFSO.GetExtensionName(strFileName) = "html" Then
handle = objExplorer.Hwnd
objExplorer.Navigate objFolder.Path + "\" + objFile.Name
For Each Wnd In oShell.Windows
If handle = Wnd.Hwnd Then Set objExplorer = Wnd
Next
Do While objExplorer.Busy
WScript.Sleep 1000 'milliseconds
Loop
objExplorer.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End If
Next
Set oShell = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set objExplorer = Nothing
第三次更新:
我修正了上面的代码。自从我使用 IE 以来,我 apologize.Its 已经有一段时间了。显然 IE 将每个选项卡视为 IE 的一个新实例,并加载一个文档 "creates" 一个新选项卡。结果,我们必须加载页面,然后再次找到我们的 IE window,以便我们可以将其设置回变量。
我有一个包含 1650 HTML 个文件的文件夹,由于地方当局的原因,这些文件也必须以纸质形式打印。
我尝试过使用经典的 ctrl+A(即使我尝试的是较小的数量),然后我在右键菜单中寻找 PRINT 标签,但没有。
如果我选择打印多个jpg或pdf文件,出现PRINT语音。
我该如何打印多个 html 文件?批处理文件? (我不知道怎么做)。
我也考虑过将 html 转换为 pdf,但使用 PDF Creator 和 PDF Architect 都没有成功。
你们有什么经验可以分享吗? 我写了一些代码,混合了 Tim 给出的代码和我在 Whosebug 上找到的代码,但没有成功。
这里是:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Users\mainUser\Desktop\ft"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
strFileName = objFile.Name
If objFSO.GetExtensionName(strFileName) = "html" Then
On Error Resume Next
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
Dim objExplorer
Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate objFolder.Path +"\"+ objFile.Name
objExplorer.Visible = 1
Do while objExplorer.ReadyState <> 4
WScript.Sleep 1000 'milliseconds
Loop
oIExplorer.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End If
Next
它只是在 Internet Explorer 中打开一个 html。我以为它会打开所有文件,并且已经在 PRINT "mode" 中。 我想我错过了什么。
查看此线程以循环访问目录中的文件:How to do something to each file in a directory with a batch script
然后您可以使用本机 PRINT
命令,这样您的批处理文件就可以像这样简单:
for /f "delims=|" %%f in ('dir /b c:\') do PRINT %%f
根据以下评论:
啊。然后,您可能必须使 IE 自动化以打印页面。按照这些行使用 VBScript:
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
objStartFolder = "C:\Users\mainUser\Desktop\ft"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set objExplorer = CreateObject("InternetExplorer.Application")
Set oShell = CreateObject("Shell.Application")
For Each objFile In objFolder.Files
strFileName = objFile.Name
If objFSO.GetExtensionName(strFileName) = "html" Then
handle = objExplorer.Hwnd
objExplorer.Navigate objFolder.Path + "\" + objFile.Name
For Each Wnd In oShell.Windows
If handle = Wnd.Hwnd Then Set objExplorer = Wnd
Next
Do While objExplorer.Busy
WScript.Sleep 1000 'milliseconds
Loop
objExplorer.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End If
Next
Set oShell = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set objExplorer = Nothing
第三次更新:
我修正了上面的代码。自从我使用 IE 以来,我 apologize.Its 已经有一段时间了。显然 IE 将每个选项卡视为 IE 的一个新实例,并加载一个文档 "creates" 一个新选项卡。结果,我们必须加载页面,然后再次找到我们的 IE window,以便我们可以将其设置回变量。