VBA:通过Internet Explorer下载文件

时间:2019-05-19 00:03:25

标签: excel vba

我正在尝试使用VBA通过Internet Explorer下载文件(安全登录后) 它是一个JSON文件,导航到该文件时,我会弹出对话框“您要打开还是保存文件”

我在帖子中尝试了许多解决方案,但是似乎都没有用,请对此提供帮助。

我尝试了来自stackoverflow,reddit和excel论坛的各种解决方案

这是我当前使用IE登录到该网站的VBA:

Sub login()
    Const Url$ = "https:/xxx.com/2020-01-01"

    Dim UserName As String, Password As String, LoginData As Worksheet
    Set LoginData = ThisWorkbook.Worksheets("Sheet1")
    UserName = LoginData.Range("A1")
    Password = LoginData.Range("A2").Value

    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")

    With ie
        .navigate Url
        ieBusy ie
        .Visible = True

        Dim oLogin As Object, oPassword As Object
        Set oLogin = .document.getElementsByName("username")(1)
        Set oPassword = .document.getElementsByName("password")(0)

        oLogin.Value = UserName
        oPassword.Value = Password
        .document.forms(0).submit    
    End With
End Sub

Sub ieBusy(ie As Object)
    Do While ie.Busy Or ie.readyState < 4
        DoEvents
    Loop
End Sub

enter image description here

0 个答案:

没有答案