【问题标题】:IE Automation - Excel VBA ... Running Into Errors After Loading WebsiteIE 自动化 - Excel VBA ...加载网站后遇到错误
【发布时间】:2016-06-30 18:12:28
【问题描述】:

我已经对 VBA 进行了相当广泛的与 IE 交互的编程,并且已经开始再次这样做,但是我遇到了一个奇怪的现象,我似乎无法通过我所做的所有研究来解决。

加载网站后,我失去了对InternetExplorer Application 的所有引用,无法再使用该对象。

当我检查网站是否已满载时,我得到了 Run-Time Error 424 Object RequiredRun-time error '-2147023179 (...)': Automation Error The interface is Unknown

如果我越过这条线(同时看到网站已满载)并运行Set doc ... 线,我会得到Run-Time Error 462: The remote server machine does not exist or is unavailable

我使用的是 IE 11 和 Excel 2010。我有对 Microsoft Internet 控件和 MicrosoftHTML 对象库的 VBAProject 引用,但后期绑定也会出现错误。

Sub LoginToFXAll()

Dim ieApp As InternetExplorer
Set ieApp = New InternetExplorer

With ieApp

    .Visible = True

    .Navigate "https://www.google.com/" 

    Do
        DoEvents
    Loop Until .ReadyState = READYSTATE_COMPLETE ''<- Run-Time Error 424 occurs here


    Dim doc As HTMLDocument
    Set doc = .Document '<- Run-Time Error 462 occurs here
    doc.all("q").Value = "Scott"

End With

End Sub

【问题讨论】:

  • 我遇到过这样的问题,您的网络是否使用了某种安全措施?如果是这样,问题是 IE 实例在验证您的“访问权限”时被“破坏”和“重建”,因此原始对象丢失
  • 感谢@Sgdva - 我确实感觉它与安全有关,但还不能“证明”。您是否找到解决它或分配新对象的方法? (我怀疑不是)。
  • 遗憾的是,我当时并没有找到解决方案,但是,现在我对此有所了解,可能您可以获得 Internet Explorer 的内存位置而不是元素本身并以某种方式引用它,遗憾的是,我目前无法测试它是否可以工作,但是,这可能是一个很好的解决方法,请查看我的回复以获取有关如何使用 ObjPtr 的指南

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


【解决方案1】:

IE创建后,可能你可以得到它的内存分配,幸运的是,在安全网络完成后会一样。

Option Explicit
#If VBA7 Then
    Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef destination As Any, ByRef source As Any, ByVal length As Long)
#Else
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef destination As Any, ByRef source As Any, ByVal length As Long)
#End If

#If VBA7 Then
Function GetMemoryAddress(ByVal IEPointer As LongPtr) As Object
#Else
Function GetMemoryAddress(ByVal IEPointer As Long) As Object
#End If
        Dim objIE As Object
        CopyMemory objIE, GetMemoryAddress, LenB(GetMemoryAddress)
        Set GetMemoryAddress = objIE
        Set objIE = Nothing
End Function

【讨论】:

  • 不错!一旦我再次遇到共享点问题,我会为我测试它-我当时没有考虑这种可能性-
猜你喜欢
  • 1970-01-01
  • 2021-01-25
  • 2014-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-25
相关资源
最近更新 更多