gpt4 book ai didi

vba - IE 自动化 - Excel VBA ...加载网站后遇到错误

转载 作者:行者123 更新时间:2023-12-04 20:59:58 24 4
gpt4 key购买 nike

我已经将 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 引用,但后期绑定(bind)也会出现错误。

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 后,您可能可以获得它的内存分配,幸运的是在安全网络完成后将是相同的。

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

关于vba - IE 自动化 - Excel VBA ...加载网站后遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38130478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com