循环打印Excel中的PDF文件
Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp _
As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private n As Integer
Sub 按钮1_Click()
lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To lMaxRows Step 1
' 打印标志为空的行进行打印
If Range("C" & x).Value = "" Then
invoicNo = Range("A" & x).Value
'拼接打印文件的路径
filePath = Range("G1").Value & "\" & "Confidential_IV(NEGO)_" & invoicNo & ".pdf"
'如果找到文件,进行打印
If Dir(filePath) <> "" Then
' 调用默认打印机打印PDF文件,SW_HIDE隐藏打印窗口
ShellExecute Application.hwnd, "print", filePath, "", "", SW_HIDE
' 调用完成后,回填信息
Range("C" & x).Value = "Confidential_IV(NEGO)_" & invoicNo & ".pdf" & "已发送给打印机。"
End If
End If
Next
End Sub
引用设置