我正在尝试让VBA Excel浏览网页上的数据表。网页将在第1页打开。我可以使用VBA Excel代码更新网页页码。(至少它看起来是有效的。)但是我似乎无法获得应用于我所请求的页面的数据来显示在屏幕上。如果我用鼠标点击下拉页面按钮,该按钮似乎是“死的”。我可以用鼠标OK成功地选择另一个页面,然后我也可以用Excel VBA OK选择我试图选择的页码。我正在使用IE。版本11,我相信它使用了分派事件。我一直在尝试各种花招,我在网上研究过,但没有成功。下面的代码是我最新的尝试。我希望比我更有经验的人能帮上忙。提前谢谢。
Sub ExtractTablesData()
Dim IE As Object
Dim obj As Object
Dim elemCollection As Object
Dim evt
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate ("http://My Web Page")
While IE.readystate <> 4 ' wait for pages to download
DoEvents
Wend
Do While IE.busy: DoEvents: Loop ' make sure page has downloaded
Set elemCollection = IE.Document.getelementsbytagname("TABLE")
Set evt = IE.Document.createEvent("HTMLEvents")
evt.initEvent "change", False, True
IE.Document.getElementsbyClassName("pager-select")(0).selectedIndex = 5
' trying to get the 6th page of data
IE.Document.getElementsbyClassName("pager-select")(0).Click
IE.Document.getElementsbyClassName("pager-select")(0).dispatchEvent (evt)
Application.Wait (Now + TimeValue("0:00:02"))
Do While IE.busy: DoEvents: Loop ' make sure page has downloaded
While IE.readystate <> 4 ' wait for pages to download
DoEvents
Wend
End With ' IE
https://stackoverflow.com/questions/41177029
复制相似问题