I have searched a lot for this topic but I didn't find a solution.
I am using IE to login a website and at some point there is a print dialogbox
and I need to click on the Print button and then the subsequent 'Save button'; in addition I need to add the pdf filename for the save.
I solved clicking the Print button with:
Private Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare PtrSafe 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, lParam As Any) As Long
Sub ClickPrintButtonWindowsAPI()
Dim hw As Long, op As Long
hw = FindWindow(vbNullString, "Print")
op = FindWindowEx(hw, 0&, "Button", vbNullString)
Call SendMessage(op, BM_CLICK, 0, 0)
End Sub
But a new window opened asking for a file name and Save button.
- The printer is "Microsoft Print to PDF" so the output would be a PDF file.
** I have downloaded spy++ but I have no experience at using it. After many tries I could select the file name
field in the dialog box and here's a snapshot
Now I tried such lines
Dim hw1 As Long
hw1 = FindWindow(vbNullString, "Save Print Output As")
Dim hw2 As Long, hw3 As Long
hw2 = FindWindowEx(hw1, 0&, "DUIViewWndClassName", vbNullString)
Dim hw4 As Long, hw5 As Long, hw6 As Long
hw3 = FindWindowEx(hw2, 0&, "DirectUIHWND", vbNullString)
hw4 = FindWindowEx(hw3, 0&, "FloatNotifySink", vbNullString)
hw5 = FindWindowEx(hw4, 0&, "ComboBox", vbNullString)
hw6 = FindWindowEx(hw5, 0&, "Edit", vbNullString)
Call SendMessageByString(hw6, &HC, 0, "Sample Text")
Dim sv As Long
sv = FindWindowEx(hw2, 0&, "Save", vbNullString)
Call SendMessage(sv, BM_CLICK, 0, 0)
A question: is there a way to make such a map simpler?
I am stuck now at clicking on the Save
button and entering the file name. Can you someone assist me with this?