【问题标题】:Get rid of Save/Open dialogue box摆脱保存/打开对话框
【发布时间】:2019-09-18 17:52:08
【问题描述】:

如何禁用 IE 询问打开或保存下载文件的消息。

我只想直接下载。没有问题。

【问题讨论】:

  • 不可能,事实上,如果可能的话,很危险......
  • How do I download a file using VBA (without Internet Explorer)。如果您可以获得要下载的文件的直接链接,这可能会起作用(或者如果需要登录或类似的东西可能会失败)。
  • 所涉及的登录名/密码。
  • @HusnainIqbal 取决于所需的身份验证类型,它可能仍然有效。请参阅链接中的解决方案。否则请参阅第一条评论。

标签: excel vba internet-explorer


【解决方案1】:

据我所知,我们不能禁用下载提示,但是我们可以使用Application.SendKeys方法发送快捷键(Alt + S)的击键来点击IE11中的保存按钮。

代码如下:

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

网页内容:

<a id="btnDowloadReport" href="https://research.google.com/pubs/archive/44678.pdf" download>Download</a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多