|
#If VBA7 And Win64 Then
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
#Else
Public Declare PtrSafe 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
#End If
Sub PrintPDFUsingAPI()
Dim PDFPath As String, result
PDFPath = ThisWorkbook.Path & "\VBA各种查询方法应用举例.pdf"
result = ShellExecute(0, "print", PDFPath, 0&, 0&, 0)
If result > 32 Then
MsgBox "打印命令已发送至默认打印机。"
Else
MsgBox "无法执行打印命令。"
End If
End Sub
|
|