IE.document.all 返回空元素 vba



有谁知道为什么这个ExplorerButton.Click在运行时返回424对象引用错误?HTML 模块已正确导入,以便能够读取与 html 相关的命令:

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

我用 --> 错误 424 表示错误。我一定是错误地引用了页面...当我查找像这样的教程时 http://qwazerty.developpez.com/tutoriels/vba/ie-et-vba-excel/,这真的很好,这就是参考的处理方式,它似乎对他有用(以及他提到的页面上的我(。所以我想我在定义按钮元素时一定省略了一些东西。任何帮助非常感谢!

谢谢! D.

页面中有一个 iframe。这就是问题所在。

您必须首先获取 iframe 元素,然后获取与 iframe 关联的文档。

文件上传按钮位于该 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 

我想你忘了像这样声明IEDoc变量:

Dim IEDoc As HTMLDocument

试试这个,它会起作用!

最新更新