【发布时间】:2011-04-19 17:14:06
【问题描述】:
我需要帮助创建一个 VBA 宏,该宏可以直接从 Yahoo Finance 的 Historic Quotes 网站下载收盘价数据并将数据导入 Excel 电子表格列。
背景资料: 这是雅虎财经历史报价数据库的链接 -
下载为 TXT 文件: http://ichart.finance.yahoo.com/table.txt?s="StockTicker"&d="EndingMonth"&e="EndingDay"&f="EndingYear"&g=d&a="EndingMonth"&b="EndingDay"&c="EndingYear"&ignore=.txt
格式问题: 默认情况下,即使用 Excel 的 Web 数据导入向导,Excel 会导入整个表格,其中包含的列比需要的多。我试图隔离“关闭”列。我创建了一个宏来格式化表格以隔离“关闭”列,但是这个宏需要我手动从雅虎财经下载数据作为 txt 文件:
Sub Test_DownloadTextFile()
Dim text As String
'The variables for this URL (in light blue) should be retrieved from the spreadsheet, i.e. "StockTicker" will reference a cell with the ticker symbol "AAPL" in it and that will appear in the URL'
text = DownloadTextFile("http://ichart.finance.yahoo.com/table.txt?s="StockTicker"&d="EndingMonth"&e="EndingDay"&f="EndingYear"&g=d&a="EndingMonth"&b="EndingDay"&c="EndingYear"&ignore=.txt")
'At this point I should have the historical quotes table stored in the variable text. How do I select the 4th column and import it into a specific spreadsheet column?'
Debug.Print text
End Sub
如何创建一个宏: 1. 指关键变量的电子表格,例如“StockTicker”、“EndingMonth”等。 2.从雅虎财经下载对应的历史数据 3. 将数据收盘价数据作为单列导入电子表格
我非常感谢这个问题的实用解决方案。如果我需要澄清我的问题或手头的任务,请告诉我。谢谢!
【问题讨论】: