PC User
Registered User.
- Local time
- Today, 00:18
- Joined
- Jul 28, 2002
- Messages
- 193
There's code for an Excel spreadsheet that I would like to use in an Access database. It downloads stock quotes from Yahoo! Its from this website: Creating an Automated Stock Trading System using Microsoft® Excel® I need advice on how to get this go work in MS Access.
Thanks,
PC User
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.AutoFit
End Sub
Sub Download()
Call GetStock("YHOO", "02/01/2007", "09/05/2008")
End Sub
PC User