IE.document.all返回null元素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 

我用 – > ERROR 424指出了错误。我必须错过引用页面的内容…当我查找这样的教程时http://qwazerty.developpez.com/tutoriels/vba/ie-et-vba-这真的是很好的结果,这就是参考文献被提出来的,似乎对他有用(对他而言,对我而言)。 所以我想我定义button元素时必须省略一些东西。 任何帮助非常感谢!

谢谢! D.

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

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

fileuploadbutton在那个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 

我想你已经忘记了像这样声明IEDocvariables:

 Dim IEDoc As HTMLDocument 

试试这个,它会工作!