엑셀 VBA에서는 Printout 메서드를 이용해 엑셀의 범위나 워크시트, 통합문서 등을 인쇄할 수 있습니다. 그런데 엑셀 이외의 다른 문서나 그림 등을 인쇄하려면 API 함수의 도움을 얻어야 합니다. 아래의 간단한 예제를 참고하세요.
Option Explicit
#If VBA7 Then
Public 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 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 dhTest()
Dim strF As String
strF = Application.GetOpenFilename("*.pdf,*.pdf")
If strF = "False" Then
Else
If dhPrintEx(strF) = 0 Then
Else
End If
End If
End Sub
Function dhPrintEx(strF As String)
dhPrintEx = ShellExecute(0&, "print", strF, vbNullString, vbNullString, vbNormalFocus)
End Function