VBA IE批准在对话框窗口

时间:2016-09-26 12:41:13

标签: excel vba excel-vba internet-explorer download

尝试使用指向文件的链接下载数据。 IE打开并导航到该文件,但弹出窗口要求我打开该文件。我需要点击这个打开按钮。请求帮助导航弹出窗口。这是我到目前为止的代码:

Sub GetData()

Const cURL = "http://www.bankofengland.co.uk/statistics/Documents/yieldcurve/ukinf05.xlsx"

Dim IE As InternetExplorer

    Dim doc As HTMLDocument

    Dim HTMLelement As IHTMLElement

    Set IE = New InternetExplorer

    IE.Visible = False
    IE.Navigate cURL


End Sub

1 个答案:

答案 0 :(得分:0)

正如@Comintern所建议的那样,稍加检查this blog entry by SiddarthRout

Option Explicit

Private Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
    ByVal szURL As String, ByVal szFileName As String, _
    ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Dim Ret As Long

Sub Sample()
    Dim strURL As String
    Dim strPath As String

    '~~> URL of the Path
    strURL = "http://www.bankofengland.co.uk/statistics/Documents/yieldcurve/ukinf05.xlsx"
    '~~> Destination for the file
    strPath = "C:\temp\ukinf05.xlsx"

    Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)

    If Ret = 0 Then
        MsgBox "File successfully downloaded"
    Else
        MsgBox "Unable to download the file"
    End If
End Sub

我得到的最终结果是文件,正确地放在我的C:\temp\文件夹中。