我有一个代码,它打开一个网页并单击一个链接。然后从一个Iframe加载数据,我试图改变下拉列表的值。使用VBA从iFrame填充网页上的下拉列表
我试图从Year
iFrame填充Manufr
下拉列表。使用VBA,但我得到Object Variable or With Block Variable not set
错误。这可能与我试图编辑的数据在Iframe中有关吗?
这里是代码我试图使用
Sub Scrape2()
Dim Browser As InternetExplorer
Dim Doc As HTMLDocument
Dim element As IHTMLElement
Set Browser = New InternetExplorer
Browser.Visible = True
Browser.navigate "http://catalog.xxxxxxx.com"
Do While Browser.Busy And Not Browser.readyState = READYSTATE_COMPLETE
DoEvents
Loop
For Each l In Browser.document.getElementsByTagName("a")
If l = "http://catalog.xxxxx.com/Catalog.asp?VehicleRef=2" Then
l.Click
Exit For
End If
Next
Stop
Set Doc = Browser.document
Dim mainIframe
Dim subIframe
Set mainIframe = Doc.frames.Item(1).document
Set subIframe = mainIframe.frames.Item(0).document
Set element = mainIframe.getElementById("Manufacturer").selectedIndex = 1
element.FireEvent ("onchange")
Set Doc = Nothing
Set Browser = Nothing
End Sub
什么是第一个链接点击吗?你是否需要等待该事件完成? –
第一个链接在文档中加载iframe。难道数据嵌入在Iframe中,导致问题? –
是的框架中的文档与您正在使用的文档不是同一文档。你需要时间来加载。 –