【发布时间】:2017-01-02 06:11:47
【问题描述】:
我有一个 VBS,它查看一组文件并将它们打印为 PDF。我现在遇到的问题是它不会打印整个工作簿。如果我可以在下面的代码中添加一个字符串?
Set fso = CreateObject("Scripting.FileSystemObject")
currentdir = fso.GetAbsolutePathName(".")
Set xmldom = CreateObject("MSXML.DOMDocument")
xmldom.Load(currentdir & "\info.xml")
progid = xmldom.SelectSingleNode("/xml/progid").text
set obj = CreateObject(progid)
printername = obj.GetPrinterName
runonce = obj.GetSettingsFileName(true)
Set fldr = fso.GetFolder(currentdir & "\in")
cnt = 0
For Each f In fldr.files
cnt = cnt + 1
output = currentdir & "\out\" & Replace(f.name, ".xls", "") & ".pdf"
obj.Init
obj.SetValue "Output", output
obj.SetValue "ShowSettings", "never"
obj.SetValue "ShowPDF", "no"
obj.SetValue "ShowProgress", "no"
obj.SetValue "ShowProgressFinished", "no"
obj.SetValue "SuppressErrors", "yes"
obj.SetValue "ConfirmOverwrite", "no"
obj.WriteSettings True
printfile = currentdir & "\in\" & f.name
cmd = """" & currentdir & "\printto.exe"" """ & printfile & """ """ & printername & """"
Set WshShell = WScript.CreateObject("WScript.Shell")
ret = WshShell.Run(cmd, 1, true)
While fso.fileexists(runonce)
wscript.sleep 100
Wend
Next
set obj = Nothing
Wscript.Echo cnt & " documents were printed."
【问题讨论】:
-
找到了一些可能有用的文章。 excel.tips.net/…stackoverflow.com/questions/5693189/…@John E