ExcelVBA批量打印PDF文件
以下是VB的代码:
首先,你系统要安装PDFREADER一类的,
然后用SHELLEXECUTE可以用默认打开方式打印
类似于你对某个文档点击右键,选择打印
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
1.
ShellExecute Me.hwnd, "Print", "D:test.doc", vbNullString, vbNullString, 0
2.
ShellExecute Me.hwnd, "Print", PDFfilename, "", "", 1
我们可以修改一下就可以用啦,如:
ShellExecute Application.hwnd, "Print", "D:test.txt", vbNullString, vbNullString, 0
完整代码如下:
=============================
'批量打印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
Sub 批量打印PDF文件()
Dim mypath, s
Dim i&
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Add "所有PDF文件", "*.pdf", 1 'PDF文件
.AllowMultiSelect = True '多选
If .Show Then mypath = .SelectedItems(1) Else Exit Sub
For i = 1 To .SelectedItems.Count
s = .SelectedItems(i)
ShellExecute Application.hwnd, "print", s, "", "", 0 'SW_HIDE
Next
End With
End Sub
。
========今天学习至此=======