[SIZE=1]Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const BM_CLICK = &HF5
Private Const WM_SETTEXT = &HC
Public Sub Print_All_PDF_Files_in_Folder()
Dim hButton As Long
Dim hEdit As Long
Dim hSaveAs As Long
Dim lngApplication As Long
Dim lngKill As Long
Dim strPDF As String
Dim strPath As String
Dim strXPS As String
strPath = "P:\mijn documenten\test\"
strPDF = strPath & Dir(strPath & "*.pdf")
Do While (strPDF <> "")
' lngApplication = Shell("C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe /t """ & strPDF & """ ""Microsoft XPS Document Writer""", vbNormalFocus)
lngApplication = Shell("C:\Program Files\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe /t """ & strPDF & """ ""Microsoft XPS Document Writer""", vbNormalFocus)
Do
' hSaveAs = FindWindow("#32770", "Printeruitvoer opslaan als") 'eventueel aanpassen "Printeruitvoer opslaan als"
hSaveAs = FindWindow("#32770", "Save the file as") 'eventueel aanpassen "Printeruitvoer opslaan als"
DoEvents
Application.Wait DateAdd("s", 1, Now())
Loop Until hSaveAs
hEdit = FindWindowEx(hSaveAs, 0, "DUIViewWndClassName", "")
hEdit = FindWindowEx(hEdit, 0, "DirectUIHWND", "")
hEdit = FindWindowEx(hEdit, 0, "FloatNotifySink", "")
hEdit = FindWindowEx(hEdit, 0, "ComboBox", "")
strXPS = Split(strPDF, ".")(0) & ".xps"
SendMessageByString hEdit, WM_SETTEXT, 0&, strXPS
' hButton = FindWindowEx(hSaveAs, 0, "Button", "&Opslaan") 'eventueel aanpassen "&Opslaan"
hButton = FindWindowEx(hSaveAs, 0, "Button", "&Save") 'eventueel aanpassen "&Opslaan"
SendMessage hButton, BM_CLICK, 0, 0
Do
' hSaveAs = FindWindow("#32770", "Printeruitvoer opslaan als") 'eventueel aanpassen "Printeruitvoer opslaan als"
hSaveAs = FindWindow("#32770", "Save the file as") 'eventueel aanpassen "Printeruitvoer opslaan als"
DoEvents
Application.Wait DateAdd("s", 1, Now())
Loop While hSaveAs
lngKill = lngApplication
Do
lngKill = Shell("TaskKill /F /IM ""AcroRd32.exe""")
DoEvents
Application.Wait DateAdd("s", 1, Now())
Loop Until lngKill <> lngApplication
strPDF = strPath & Dir
Loop
End Sub[/SIZE]