0

How to disable the message of IE asking open or save download file.

I just want to download it directly. no question asked.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Husnain Iqbal
  • 89
  • 1
  • 10
  • 1
    Not possible, and in fact, dangerous if it was possible... – braX Sep 18 '19 at 06:00
  • See [How do I download a file using VBA (without Internet Explorer)](https://stackoverflow.com/questions/17877389/how-do-i-download-a-file-using-vba-without-internet-explorer). This might work if you can get the direct link to the file you want to download (or might fail if a login or something similar is required). – Pᴇʜ Sep 18 '19 at 06:20
  • Login/Password in involved. – Husnain Iqbal Sep 18 '19 at 06:21
  • @HusnainIqbal depending on the kind of authentication that is required it might still work. See the solution in the link. Otherwise see the first comment. – Pᴇʜ Sep 18 '19 at 06:23

1 Answers1

0

As far as I know, we can't disable the download prompt, but we could use the Application.SendKeys method to send the keystrokes of the shortcut keys (Alt + S) to click the save button in IE11.

Code as below:

Sub downloadfile()

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

    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Visible = True
        .navigate ("<the website url>")

        While IE.ReadyState <> 4
            DoEvents
        Wend

        Set Data = IE.Document.getElementsbyTagName("input")

        '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