0
我有一個VBS查看一組文件並將它們打印到PDF。我現在遇到的問題是它不打印整個工作簿。如果有一個字符串,我可以添加到下面的代碼?VBS命令告訴excel打印整個工作簿
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."
找到一些可能會對你有幫助的文章。 http://excel.tips.net/T002001_Printing_an_Entire_Workbook_by_Default.html http://stackoverflow.com/questions/5693189/excel-vb-script-to-print-all-workbooks-sheets @John E –