我需要帮助创建一个VBA宏,它直接从Yahoo Finance的历史行情网站下载收盘价数据并将数据导入到Excel电子表格列中。使用Excel VBA下载和格式化Web数据
背景资料: 这是链接到雅虎财经的历史报价数据库 -
下载TXT文件: http://ichart.finance.yahoo.com/table.txt?s= “StockTicker” & d = “EndingMonth” & E = “EndingDay” & F = “EndingYear” & G = d &一个= “EndingMonth” & b = “EndingDay” & C = “EndingYear” &忽略= .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.进口数据收盘价数据,一列到电子表格
我非常欣赏一个切实可行的解决方案解决这个问题。如果我需要澄清我的问题或手头的任务,请告诉我。谢谢!
谢谢你的链接。我喜欢将txt文件存储在变量中的想法。当用户更改股票代码,开始和结束日期等时,是否可以改变动态网址?此外,现在数据存储在一个变量中,选择一个特定的列并将该列导入到电子表格中应该相对简单,对吧?感谢您的帮助。 – AME 2010-10-01 22:06:10