Acrobat Reader PDF von Excel ausdrucken
29.08.2006 16:21:44
Excel
ich möchte gerne von Excel aus eine bestimmte pdf-Datei ausdrucken. das klappt auch ganz gut. Aber nach dem Drucken bleibt vom Acrobat Reader immer noch eine leere Instanz geöffnet. Ich möchte aber dass der Acrobat Reader nach dem Drucken ganz geschlossen wird.
Vielen Dank für Eure Hilfe!!
Ich habe diesen Code verwendet:
Option Explicit
Private Declare Function FindClassWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As Long) _
As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Function ShellExecuteAPI 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
Private Const SW_HIDE = 0
Public Function PrintDocument(ByVal documentAndpath$) As Long
'Druckt jedes Dokument für das eine Druckverknüpfung in
'der Registry hinterlegt ist
PrintDocument = ShellExecuteAPI(0, "print", documentAndpath, "", "", SW_HIDE)
End Function
Public Function CloseClassWindow(ByVal class$) As Boolean
'Acrobat=AdobeAcrobat
'Klassenname des Hauptfensters übergeben
'Liefert true zurück, falls ein Fenster gefunden wurde
'schließt das erste gefundene Fenster
Dim hwnd&
hwnd = FindClassWindow(class$, 0&)
If hwnd Then
CloseClassWindow = True
Call PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, ByVal 0&)
End If
End Function
Private Sub cmdPrint_PDF_Click()
Dim str As String
str = Application.ThisWorkbook.Path
str = str & "/test.pdf"
PrintDocument str
CloseClassWindow "AdobeAcrobat"
End Sub