asdzxc
05-22-2012, 05:45 AM
In J1, put ^dji
whether put w or m in I1, both give daily data
StrURL = "URL;http://ichart.finance.yahoo.com/table.csv?s=" & [Sheet1!J1].Value
If Range("I1").Value = d Then
StrURL = StrURL & "&a=3&b=15&c=2012&d=06&e=6&f=2013" _
& "&g=d&ignore=.xlsx"
End If
If Range("I1").Value = w Then
StrURL = StrURL & "&a=10&b=13&c=2011&d=06&e=6&f=2013" _
& "&g=w&ignore=.xlsx"
End If
If Range("I1").Value = m Then
StrURL = StrURL & "&a=10&b=13&c=2009&d=06&e=6&f=2013" _
& "&g=m&ignore=.xlsx"
End If
With ActiveSheet.QueryTables.Add(Connection:=StrURL, Destination:=Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub
whether put w or m in I1, both give daily data
StrURL = "URL;http://ichart.finance.yahoo.com/table.csv?s=" & [Sheet1!J1].Value
If Range("I1").Value = d Then
StrURL = StrURL & "&a=3&b=15&c=2012&d=06&e=6&f=2013" _
& "&g=d&ignore=.xlsx"
End If
If Range("I1").Value = w Then
StrURL = StrURL & "&a=10&b=13&c=2011&d=06&e=6&f=2013" _
& "&g=w&ignore=.xlsx"
End If
If Range("I1").Value = m Then
StrURL = StrURL & "&a=10&b=13&c=2009&d=06&e=6&f=2013" _
& "&g=m&ignore=.xlsx"
End If
With ActiveSheet.QueryTables.Add(Connection:=StrURL, Destination:=Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub