【问题标题】:Close IE after download file by direct link通过直接链接下载文件后关闭 IE
【发布时间】:2020-10-29 07:29:31
【问题描述】:

我使用此代码通过 IE 从直接下载链接下载文件。但是当它运行时我卡住了 IE.quit,运行时错误462:远程服务器机器不存在。这是我的代码:

Sub Download ()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Dim a, l As Integer
Sheet3.Select
Range("A1").Select
l = Range(Selection, Selection.End(xlDown)).Rows.Count
For a = 1 To l
IE.Visible = True
IE.navigate Cells(a, 2)
Application.Wait (Now + TimeValue("0:00:15"))
Application.SendKeys "%{S}"
Application.Wait (Now + TimeValue("0:00:2"))
IE.Quit
IE = Nothing
Next a
End Sub

请帮我解决这个问题。非常感谢

【问题讨论】:

  • 您好,请问这个问题呢?我下面的回答对解决这个问题有帮助吗?如果是这样,您可以参考this,它可以帮助其他社区成员将来解决类似问题。感谢您的理解。

标签: vba internet-explorer hyperlink download


【解决方案1】:

我认为这是因为您在循环外创建了 IE 对象,但在循环中释放了 IE 对象。你在循环中释放它,所以当它第二次循环时,你不能再使用它了。你可以在循环结束后释放IE。另外,IE = Nothing之前应该有一个Set

代码应如下所示:

Sub Download()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Dim a, l As Integer
Sheet2.Select
Range("A1").Select
l = Range(Selection, Selection.End(xlDown)).Rows.Count
For a = 1 To l
IE.Visible = True
IE.navigate Cells(a, 2)
Application.Wait (Now + TimeValue("0:00:15"))
Application.SendKeys "%{S}"
Application.Wait (Now + TimeValue("0:00:2"))
Next a
IE.Quit
Set IE = Nothing
End Sub

【讨论】:

    猜你喜欢
    • 2017-09-11
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2012-10-05
    相关资源
    最近更新 更多