对象“IWebBrowser2”的Excel VBA“Method'Document'失败” [英] Excel VBA "Method 'Document' of object 'IWebBrowser2' failed"
问题描述
我正在Excel中自动执行表单提交工作,并且在基础上遇到麻烦。我收到错误消息:
I'm trying to automate a form submission in Excel for work, and In have trouble with the basics. I keep getting the error message:
对象IWebBrowser2的方法'文档'失败
"Method 'Document' of object 'IWebBrowser2' failed"
随着代码的原样,如果我在等待检查中包含或部分,我会收到错误
With the code as is, and if I include the Or part in the waiting check, I get the error
自动化错误调用的对象与客户端断开连接。
"Automation Error The object invoked has disconnected from its clients."
我不知道在这里做,我搜索了所有的解决方案。这个代码最终要做的比这更多,但是在第一次尝试 getElementsByTagName
之前,它会继续失败。
I'm not sure what to do here, I've searched all over for solutions. This code is intended to eventually do more than this, but it keeps failing on the first try to getElementsByTagName
.
Sub GoToWebsiteTest()
Dim appIE As Object 'Internet Explorer
Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
If appIE Is Nothing Then Set appIE = CreateObject("InternetExplorer.Application")
sURL = *link*
With appIE
.Visible = True
.Navigate sURL
End With
Do While appIE.Busy ' Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName("input")
Set appIE = Nothing
End Sub
推荐答案
我遇到同样的问题。在中等完整性级别使用互联网浏览器。 InternetExplorer默认为低完整性级别,如果您在工作中通过本地Intranet执行此操作,有时会给出上面显示的第二条错误消息。
点击这里,以便更多阅读。我在下面修改了你的代码请让我知道,如果这有帮助。
I ran into this same issue a while back. Use internet explorer at a medium integrity level. InternetExplorer defaults to a low integrity level which, if you are doing this over a local intranet at work, sometimes will give the second error message you show above. Click here for more reading on this. I've modified your code below. Please let me know if that helps.
Sub GoToWebsiteTest()
Dim appIE As InternetExplorerMedium
'Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "http://example.com"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName("input")
Set appIE = Nothing
End Sub
记住Microsoft Internet Controls的参考资料,具体取决于您进一步的计划,Microsoft HTML对象库
Remember references for Microsoft Internet Controls, and depending on what you plan on doing further, Microsoft HTML Object Library
这篇关于对象“IWebBrowser2”的Excel VBA“Method'Document'失败”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!