IE.document.all返回null元素vba
问题描述:
有谁知道为什么这个ExplorerButton.Click
在运行时返回424对象引用错误? HTML模块正确导入到能够阅读HTML相关命令:IE.document.all返回null元素vba
Private Sub Generate_Click()
Dim IE As New InternetExplorer
Dim ExplorerInput As HTMLInputElement
Dim ExplorerButton As HTMLInputElement
'Loading Page
IE.navigate "https://www.earthpoint.us/ExcelToKml.aspx"
'Show Window
IE.Visible = True
'Wait for loade
WaitIE IE
'Select document
Set IEDoc = IE.document
'Select Button
Set ExplorerButton = IEDoc.all.Item("FileUpload1")
'Click button
ExplorerButton.Click --> ERROR 424
End Sub
Sub WaitIE(IE As InternetExplorer)
'Loop until load
Do Until IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
End Sub
我指出错误 - > ERROR 424我一定是错过引用的页面......当我抬头看教程一样这一个http://qwazerty.developpez.com/tutoriels/vba/ie-et-vba-excel/,这真的很好地引起了,这是参考如何被支持,它似乎为他(和他在我提到的页面上)为他工作。所以我想在定义按钮元素时我必须省略一些东西。任何帮助非常感谢!
谢谢! D.
答
页面中有一个iframe。这是问题。
您必须先获取iframe元素,然后获取与iframe关联的文档。
fileupload按钮位于该iframe中。
IE.navigate "https://www.earthpoint.us/ExcelToKml.aspx"
'Show Window
IE.Visible = True
'Wait for loaded
WaitIE IE
'Select document
Set IEDoc = IE.document
Dim iBox As HTMLIFrame
Set iBox = doc.all("iframe1")
Dim iframeDoc As HTMLDocument
Set iframeDoc = iBox.contentDocument
'Select Button
Set ExplorerButton = iframeDoc.all.Item("FileUpload1")
'Click button
ExplorerButton.Click --> ERROR 424
非常感谢你!无法直接访问该项目,但通过iframe,这确实有效。 – Diveye