【发布时间】:2014-01-13 20:21:29
【问题描述】:
设置对 Microsoft XML V6.0 的引用后,以下代码按预期工作,恢复了“buy_max”的所需值
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.Load ("http://api.eve-central.com/api/marketstat?typeid=24692&usesystem=30000142")
buy_max = xmlDoc.getElementsByTagName("buy")(0).getElementsByTagName("max")(0).Text
另一方面,以下代码无法恢复“buy_max”的值。而是产生错误(运行时错误 91“对象变量或未设置块变量”)。
my_url = "http://api.eve-central.com/api/marketstat?typeid=24692&usesystem=30000142"
Set html_doc = CreateObject("htmlfile")
Set xml_obj = CreateObject("MSXML2.XMLHTTP")
xml_obj.Open "GET", my_url, False
xml_obj.send
html_doc.body.innerhtml = xml_obj.ResponseText
buy_max = html_doc.getElementsByTagName("buy")(0).getElementsByTagName("max")(0).innertext
谁能解释为什么第二种方法会失败? TIA,罗恩
【问题讨论】:
-
您在哪一行得到异常?
-
当我尝试执行“buy_max = html_doc.getElementsByTagName...”行时
标签: xml vba excel getelementsbytagname