0

I have taken code off the boards to send-Keys to the IE11 Save/Open box that pop-ups when you export a file but it is not working (it is sending to the main browser). I cannot activate the Save/Open box & send the S button even when trying manually (using ALT + S)

Do you require some settings to be able to send keys to this pop-up?

I have put a condensed version of the code below

Thanks

Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As LongPtr) As LongPtr

Sub OpenIE()

Dim objIE As InternetExplorer
Set objIE = New InternetExplorer

Dim HWNDSrc As LongPtr
HWNDSrc = objIE.HWND
SetForegroundWindow HWNDSrc


'From https://stackoverflow.com/questions/56893185/controlling-ie11-do-you-want-to-open-save-vba
 Do While objIE.Busy
                Application.Wait DateAdd("s", 1, Now)
            Loop

        'send Alt-S to save
            Application.SendKeys "%{S}"

 'Make sure IE is not busy
             Do While objIE.Busy
                 Application.Wait DateAdd("s", 1, Now)
             Loop

braX
  • 11,506
  • 5
  • 20
  • 33
Mturks83
  • 89
  • 2
  • 9

1 Answers1

0

Please refer to the following sample code, we could use getElementbyId method to find the download button first, then click it to display the download prompt, after that, we could using the Application.SendKeys "%{s}" command to click the Save button.

Sub downloadfile()

    Dim IE As Object, Data As Object
    Dim ticket As String

    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Visible = True
        .navigate ("https://dillion132.github.io/default.html")

        While IE.ReadyState <> 4
            DoEvents
        Wend

        'Trigger the download button to download the file
        IE.Document.getElementbyId("btnDowloadReport").Click

        'wait the download prompt appear
        Application.Wait (Now + TimeValue("00:00:03"))

        '
        Application.SendKeys "%{s}"

    'Waiting for the site to load.
    'loadingSite
    End With
    Set IE = Nothing
End Sub

The web page content:

<a id="btnDowloadReport" href="https://research.google.com/pubs/archive/44678.pdf" download>Download</a>
Zhi Lv
  • 18,845
  • 1
  • 19
  • 30