Cannot download file from Internet Explorer 11 dialog box

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 doesnot 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

By: Ramandeep Singh

Leave a Reply

Your email address will not be published. Required fields are marked *