【发布时间】:2016-07-09 14:19:00
【问题描述】:
我正在尝试使用 VBA 脚本 excel 宏 link 从站点下载数据,但我感兴趣的数据位于网页框架内,主页和框架的 url 没有改变。
以下是在主页上运行良好的宏,请帮助我从网络框架中下载相同的宏。
'Microsoft HTML Office Library
Sub webtable_NSE()
Dim HTMLDoc As New HTMLDocument
Dim objElementsTd As Object
Dim objTd As Object
Dim lRow As Long
Dim myarray()
Dim oIE As InternetExplorer
Set oIE = New InternetExplorer
oIE.navigate "https://www.nseindia.com/products/content/equities/ipos/ipo_current_quess.htm"
'javascript:loadIpoBidDetails('/products/content/equities/ipos/Quess_curr_ipo_bid_details.htm')
'oIE.Navigate "https://www.nseindia.com/products/content/equities/ipos/Quess_curr_ipo_bid_details.htm"
Do Until (oIE.readyState = 4 And Not oIE.Busy)
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:03"))
HTMLDoc.body.innerHTML = oIE.Document.body.innerHTML
With HTMLDoc.body
Set elemcollection = .getElementsByTagName("Table")
For t = 0 To elemcollection.Length - 1
For r = 0 To elemcollection(t).Rows.Length - 1
For c = 0 To elemcollection(t).Rows(r).Cells.Length - 1
ThisWorkbook.Sheets("NSE").Cells(ActRw + r + 1, c + 1) = elemcollection(t).Rows(r).Cells(c).innerText
Next c
Next r
ActRw = ActRw + elemcollection(t).Rows.Length + 1
Next t
End With
oIE.Quit
End Sub
【问题讨论】: