【问题标题】:VBS Command to tell excel to print entire workbookVBS 命令告诉 excel 打印整个工作簿
【发布时间】: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 vbscript


【解决方案1】:

我相信 printto.exe 是第 3 方实用程序,可从 http://www.reasoft.com/products/pdfprinter/help/using/se/command.html 获得

您可能需要联系软件供应商以验证该实用程序是否支持您想要的功能。

无论如何,您可能希望遵循上面@randy-schuman 指出的建议,而不是使用第 3 方实用程序,即从 Excel 应用程序触发打印。您可以执行以下操作:

Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = False

For Each f In fldr.Files
  If Instr(f.Type,"Excel") Then
    Set book = objExcel.Workbooks.Open(f.Path,0,1)
    book.PrintOut ,,,,printername  '' https://msdn.microsoft.com/en-us/library/office/ff196840.aspx
    book.Close 0
  End If
Next

objExcel.Quit
Set objExcel = Nothing

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 2023-03-24
    • 2017-08-02
    • 1970-01-01
    相关资源
    最近更新 更多