【发布时间】:2017-08-31 08:43:36
【问题描述】:
首先我不是程序员,我只是想通过在 Excel 中输入一些输入数据来从https://www.nseindia.com/products/content/equities/equities/eq_security.htm 下载报价历史。我以某种方式设法将数据放入 VBA。谁能帮助我如何点击“以 CSV 格式下载文件”并将其保存到我的本地磁盘。
这是我的 VBA 代码:
Private Sub CommandButton1_Click()
Dim IE As Object
With IE
Set IE = CreateObject("InternetExplorer.Application")
'create new instance of IE. use reference to return current open IE if
'you want to use open IE window. Easiest way I know of is via title bar.
IE.Navigate "https://www.nseindia.com/products/content/equities/equities/eq_security.htm"
'go to web page listed inside quotes
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
IE.document.ALL("symbol").Value = ThisWorkbook.Sheets("sheet1").Range("b1")
IE.document.ALL("series").Value = ThisWorkbook.Sheets("sheet1").Range("b2")
IE.document.getElementById("rdDateToDate").Click
IE.document.ALL("fromDate").Value = ThisWorkbook.Sheets("sheet1").Range("b4")
IE.document.ALL("toDate").Value = ThisWorkbook.Sheets("sheet1").Range("c4")
IE.document.getElementById("submitMe").Click
End With
End Sub
【问题讨论】:
-
您能提供
Symbol和Series的值吗?理想的From Date和To Date也是如此,但它们并不重要 -
Symbol=SBIN, Series=EQ, From date=01-01-2012 & To Date=01-12-2012
-
请提供下载文件后自动关闭IE的代码。谢谢。
标签: vba excel internet-explorer