有谁知道为什么这个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/这样的教程时,这很好地带来了,这就是参考文献的用法,它似乎对他有效(在他提到的页面上对我来说。所以我想在定义button元素时我必须省略一些东西。任何帮助非常感谢!
谢谢! d。
答案 0 :(得分:2)
页面中有一个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
答案 1 :(得分:1)
我认为您已经忘记了像这样声明IEDoc变量:
Dim IEDoc As HTMLDocument
试试这个,它会起作用!