IE自动化 – Excel VBA …加载网站后出现错误

我已经将VBA编程为与IE进行了相当广泛的交互,并且已经开始这样做了,但是我遇到了一个奇怪的现象,我无法用我所做的所有研究来解决这个问题。

只要我加载的网站,我失去了InternetExplorer Application所有参考,并不能再与对象工作。

当我检查站点被完全加载,我得到一个Run-Time Error 424 Object Required ,或Run-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 

在创buildIE后,可能会得到内存分配,幸运的是安全networking完成后,

 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