【问题标题】:VBA automation error in CreateObject("InternetExplorer.Application")CreateObject(“InternetExplorer.Application”)中的 VBA 自动化错误
【发布时间】:2020-10-20 01:51:09
【问题描述】:

我在调用以下对象时遇到自动化错误

Set IE = CreateObject("InternetExplorer.Application")

显示错误

运行时错误“-2147467259 (80004005)” 自动化错误 未指明的错误

谁能知道为什么会发生这种情况

'从 cmets 移动代码

Sub TableExample()

    Dim IE As Object
    Dim doc As Object
    Dim strURL As String
    strURL = Range("B2").Value

    Set IE = CreateObject("InternetExplorer.Application")
    With IE '
        .Visible = True
        .navigate Range("B2").Value
        Do Until .readyState = 4
            DoEvents
        Loop
        Do While .Busy
            DoEvents
        Loop
        Set doc = IE.document
        GetAllTables doc
        .Quit
    End With
End Sub

【问题讨论】:

  • 做了一些搜索,找到了一些相关信息。 1) 你有“启用保护模式”吗? 2) 改用Set IE = New InternetExplorerMedium
  • 嘿,山姆,我也找到了这些想法,但所有这些都在这里失败了......
  • 你以何种方式声明IE variable
  • 如果使用早期绑定会怎样?
  • @sam092 早期绑定没有帮助...

标签: vba excel


【解决方案1】:

我只是在这个问题上浪费了 4 个小时,而且我对解决方案的简单程度感到震惊。 每次运行该行时,Excel 都会创建一个新的 activeX 实例:

Set IE = CreateObject("InternetExplorer.Application")

它的具体工作原理超出了我的范围,但即使在您重新启动 excel 后,这些参考资料仍然存在。堆了几十个后,excel用完了内存来做更多

重新启动您的计算机,(可能是一种更简单的方法,但这对我有用) 然后坚持下去

IE.Quit 

在代码的末尾

【讨论】:

  • 可以关闭当前浏览器上的所有Internet Explorer实例,Windows->执行->输入cmd,然后输入taskkill /F /IM iexplore.exe
【解决方案2】:

对于其他最终出现相同错误的人...

这也可能是由于在已退出并设置为空的 InternetExplorer 对象中引用 Document 对象属性引起的。这不是这个问题中发生的事情,而是以下代码引发了同样的错误。

Dim ie As New InternetExplorer
ie.Visible = True
ie.Navigate "google.com"

ie.Quit
Set ie = Nothing

If ie.Document Is Nothing Then 'Error thrown here
    MsgBox "Can't get here"
End If

【讨论】:

    【解决方案3】:

    添加代码以确保所有 IE 浏览器在 Set 行之前完全关闭。
    `Set IE = CreateObject("InternetExplorer.Application")`

    将其更改为:
    调用 IE_Sledgehammer
    设置 IE = CreateObject("InternetExplorer.Application")

    将 Sledgehammer 模块作为自己的宏添加到工作簿的其他位置:

    Sub IE_Sledgehammer()
    Dim objWMI As Object, objProcess As Object, objProcesses As Object
    设置 objWMI = GetObject("winmgmts://.")
    设置 objProcesses = objWMI.ExecQuery( _
    "SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")
    对于 objProcesses 中的每个 objProcess
    On Error Resume Next
    调用 objProcess.Terminate
    下一页
    设置 objProcesses = 无:设置 objWMI = 无
    结束子

    【讨论】:

      猜你喜欢
      • 2021-11-04
      • 1970-01-01
      • 2018-12-19
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 2018-12-18
      • 1970-01-01
      相关资源
      最近更新 更多