我遇到了一个
Object不支持此属性或方法
excel vba中的运行时错误。
注意:代码在我的笔记本电脑上工作正常。当我将代码迁移到我的桌面电脑时发生了这个错误。
以下是更新的代码。
Dim ie As InternetExplorer
Dim htmldoc As MSHTML.IHTMLDocument
Dim ro1 As MSHTML.IHTMLElementCollection
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.navigate "url"
Set htmldoc = ie.document
Set ro1 = htmldoc.getElementById("table id").getElementsByTagName("tr")
ThisWorkbook.Sheets(1).Cells(k, j) = rows(k).Children(0).textContent
ro1(k).Children(0).textContent
是错误的一部分。
我查看了工具 - >参考文献。已检查Microsoft Internet Controls和Microsoft HTML Object Library。
有人可以指导我吗?
尝试使用InnerText而不是textContent
,看看它是否适合你。
ThisWorkbook.Sheets(1).Cells(k, j) = rows(k).Children(0).InnerText
首先在模块顶部添加一行Option Explicit
,然后在Debug
-> Compile
中添加未正确声明或被滥用的变量和对象,继续编译直到不再有警告。
另外,不要使用单词ROWS
作为对象名称。 Rows
已经在Excel和VBA中意味着什么。
Here is a list of reserved words应该避免。 (我意识到它被标记为Access 2007,但列表非常相似,并且很难找到Excel VBA最近的“官方”列表。)