我无法弄清楚如何按顺序打印PDF文件(单元格列表的顺序)。
Sub PrintPDFFiles()
zProg = "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe"
zLastRow = [a65536].End(xlUp).Row
temp = "a1:a" & zLastRow
zPrinter = "HP LaserJet Professional M1213nf MFP "
For Each cell In Range(temp)
zFile = cell.Value
If zFile Like "*.pdf" Then
Shell """" & zProg & """/n /h /t""" & zFile & """"
End If
Next
End Sub
到目前为止我做过的研究:
没有命令行switch按顺序打印文件。
更新-1 MyCode建议后:
我在代码中使用了object.run方法,我收到错误:
Sub PrintPDFFiles()
zProg = "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe"
zLastRow = [a65536].End(xlUp).Row
temp = "a1:a" & zLastRow
zPrinter = "HP LaserJet Professional M1213nf MFP "
For Each cell In Range(temp)
zFile = cell.Value
If zFile Like "*.pdf" Then
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
zCommand = zProg & " /n /h /t " & Chr(34) & zFile & Chr(34) & " " & zPrinter
wsh.Run zCommand, windowStyle, waitOnReturn
End If
Next
End Sub
错误:
更新-2我的代码建议后:
wsh.Run """Acrobat.exe"" /n /h /t" & Chr(34) & zfile & Chr(34) & " " & zPrinter, , waitOnReturn
问题: 我设法使用run方法打印,但是我必须在每个文件后关闭Adobe Acrobat Reader。我必须打印500多个文件。
答案 0 :(得分:0)
我用GhostScript修改代码
Sub PrintPDFFiles()
zProg = "gsprint -printer printerName -dPDFFitPage "
zLastRow = [a65536].End(xlUp).Row
Dim Counter As Integer
For Counter = 1 To zLastRow
zFile = Worksheets("Sheet1").Cells(Counter, 1).Value ' Where 1 is the first column
If zFile Like "*.pdf" Then
Shell """" & zProg & zFile & """"
End If
Next Counter
End Sub
答案 1 :(得分:0)
如果文件目录中存在文件,请使用this从单元格列表中打印所有类型的文件。基本上,该软件按顺序打印所有类型的文件。