I would like to update the following macro so that it becomes a user defined function like GetQuote(date,tickersymbol) where you input the date and the ticker symbol and it pulls the adjusted close price from Yahoo. Thanks for your help!
Macro courtesy of http://www.spreadsheetml.com/finance/freedownloadofstockquotes.shtml
</PRE>
Macro courtesy of http://www.spreadsheetml.com/finance/freedownloadofstockquotes.shtml
Code:
Sub GetStock(ByVal stockSymbol As String, ByVal StartDate As Date, ByVal EndDate As Date) Dim DownloadURL As String Dim StartMonth, StartDay, StartYear As String Dim EndMonth, EndDay, EndYear As String StartMonth = Format(Month(StartDate)-1, "00") StartDay = Format(Day(StartDate), "00") StartYear = Format(Year(StartDate), "00") EndMonth = Format(Month(EndDate)-1, "00") EndDay = Format(Day(EndDate), "00") EndYear = Format(Year(EndDate), "00") DownloadURL="URL;http://table.finance.yahoo.com/table.csv?s=" + stockSymbol + "&a=" + StartMonth + "&b=" + StartDay + "&c=" + StartYear + "&d=" + EndMonth + "&e=" + EndDay + "&f=" + EndYear + "&g=d&ignore=.csv" With ActiveSheet.QueryTables.Add(Connection:=DownloadURL, Destination:=Range("$A$1")) .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "20" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With ActiveWindow.SmallScroll Down:=-12 Columns("A:A").TextToColumns Destination:=Range("A1"),_ DataType:=xlDelimited, TextQualifier:=xlDoubleQuote,_ ConsecutiveDelimiter:=False,_ Tab:=True,_ Semicolon:=False, Comma:=True, Space:=False,_ Other:=False,_ FieldInfo:=Array(Array(1, 1), Array(2, 1),_ Array(3, 1), Array(4, 1),_ Array(5, 1), Array(6, 1), Array(7, 1)) Columns("A:F").EntireColumn.AutoFitEnd SubSub Download() Call GetStock("YHOO", "02/01/2007", "09/05/2008")End Sub</PRE>