使用Excel VBA下载和格式化Web数据

我需要帮助创build一个VBAmacros,直接从雅虎财经的历史行情网站下载收盘价数据,并将数据导入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” &忽略= .TXT

格式问题:默认情况下,即使用Excel的Web数据导入向导,Excel导入包含更多列的整个表。 我正试图隔离“closures”列。 我创build了一个macros来格式化表格以隔离“close”列,但是这个macros需要我手动从Yahoo Finance手动下载数据作为txt文件:

Sub Test_DownloadTextFile() Dim text As String 'The variables for this URL (in light blue) should be retrieved from the spreadsheet, ie "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 

我怎样才能创build一个macros:1.引用关键variables的电子表格,例如“StockTicker”,“EndingMonth”等。2.从Yahoo Finance下载相应的历史数据3.导入数据收盘价数据为单列到电子表格中

我非常感谢这个问题的实际解决scheme。 让我知道,如果我需要澄清我的问题或手头的任务。 谢谢!

build议:这似乎是一个Web查询的理想情况。
你有什么理由不使用它? 您可以复制以后需要的列。 你没有指定你的Excel版本,但在2003年它是在数据/导入外部数据。

看看这个讨论 。 几个似乎值得的build议。