我已经将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 Controls和MicrosoftHTML Object Library的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
答案 0 :(得分:0)
创建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