Cannot download file from IE11 dialog box using vba

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.75 out of 5)
Loading...
Go back to All Questions Login or Register
615 views
0

Hi,
I have created a code which will login in a website and when it click on export to download a file, IE displays a dialog box stating open,save and save as button inspite of several attempts my code doesn’t clicks on save button,following is my code:

Sub Save_Over_Existing_Click_Yes()

Dim hwnd As Long
Dim timeout As Date

Debug.Print “Save_Over_Existing_Click_Yes”

‘Find the Download complete window, waiting a maximum of 30 seconds for it to appear. Timeout value is dependent on the
‘size of the download, so make it longer for bigger files

timeout = Now + TimeValue(“00:00:40”)
Do
hwnd = FindWindow(“#32770”, “Internet Explorer”)
MsgBox hwnd
DoEvents
Sleep 200
Loop Until hwnd Or Now > timeout
‘ Debug.Print ” Save As window “; Hex(hwnd)

If hwnd Then
‘Find the child Close button
hwnd = FindWindowEx(hwnd, ByVal 0&, “Button”, vbNullString)

‘hwnd = FindWindowEx(hwnd, 0, “Button”, “&Save”)
‘ Debug.Print ” save button “; Hex(hwnd)
End If
MsgBox hwnd
If hwnd Then

‘Click the Close button
MsgBox 1
SetForegroundWindow (hwnd)
Sleep 6000 ‘this sleep is required and 600 miiliseconds seems to be the minimum that works
Const BM_CLICK As Long = &HF5&
SendMessage hwnd, BM_CLICK, 0, 0
End If
End Sub

Thanks,
Ramandeep Singh

0

Personally I do not think using FindWindow is very reliable. Try simply simulating the “Save” button like so:

You are viewing 1 out of 1 answers, click here to view all answers.

Simply the best place to learn VBA!