Excel 从网站下载文件

Excel 从网站下载文件,excel,vba,macos,Excel,Vba,Macos,我在Mac上使用Excel 2011,这意味着我无法(或至少我不知道如何)导航到网页并将下载链接中的数据保存到Excel工作簿中。 在这个网站上, 有一个“下载数据”按钮。我试图将这些数据输入Excel,以便计算出5年的标准偏差。谢谢 我遇到的一个问题是,您必须向下滚动才能查看所有日期,因此当我将数据输入到查询表中时,它只会从最初显示的日期中提取数据。好的,我现在明白了。查看下面的链接 从标题为“获取Excel电子表格以从Google Finance下载大量历史股票数据”的链接下载该文件。那

我在Mac上使用Excel 2011,这意味着我无法(或至少我不知道如何)导航到网页并将下载链接中的数据保存到Excel工作簿中。 在这个网站上,

有一个“下载数据”按钮。我试图将这些数据输入Excel,以便计算出5年的标准偏差。谢谢


我遇到的一个问题是,您必须向下滚动才能查看所有日期,因此当我将数据输入到查询表中时,它只会从最初显示的日期中提取数据。

好的,我现在明白了。查看下面的链接

从标题为“获取Excel电子表格以从Google Finance下载大量历史股票数据”的链接下载该文件。那会给你你想要的。我将在这里发布代码,但它相当广泛,可能不一定有用

萨米尔·汗 'simulationconsultant@gmail.com '此电子表格的最新版本可从http://investexcel.net/multiple-stock-quote-downloader-for-excel/ '请链接到http://investexcel.net 如果你喜欢这个电子表格 子下载股票报价(ByVal stockTicker作为字符串,ByVal StartDate作为日期,ByVal EndDate作为日期,ByVal DestinationCell作为字符串,ByVal freq作为字符串) 暗qurl As字符串 Dim StartMonth、StartDay、StartYear、EndMonth、EndDay、EndYear作为字符串 qurl=”http://finance.google.com/finance/historical?q=“&stockTicker” qurl=qurl&“&startdate=“&MonthName(Month(startdate),True)”和_ “+”&天(起始日期)&“+”&年(起始日期)&_ “&enddate=”&MonthName(月(enddate),True)和_ “+”&天(结束日期)&“+”&年(结束日期)&“&输出=csv” 错误转到错误处理程序时: 查询引述: 使用ActiveSheet.QueryTables.Add(连接:=“URL;”&qurl,目标:=范围(DestinationCell)) .BackgroundQuery=True .TablesOnlyFromHTML=False .Refresh BackgroundQuery:=False .SaveData=True 以 错误处理程序: 端接头 子下载数据() 将频率变为字符串 作为整数的Dim numRows 将最后一行设置为整数 将lastErrorRow设置为整数 将lastSuccessRow设置为整数 作为字符串的Dim stockTicker 作为整数的Dim NUMSTOCKERS Dim numStockSuccess为整数 numStockErrors=0 numStockSuccess=0 Application.Calculation=xlCalculationManual Application.ScreenUpdating=False lastErrorRow=ActiveSheet.Cells(Rows.Count,“J”).End(xlUp).Row lastSuccessRow=ActiveSheet.Cells(Rows.Count,“L”).End(xlUp).Row ClearErrorList lastErrorRow ClearSuccessList lastSuccessRow lastRow=ActiveSheet.Cells(Rows.Count,“a”).End(xlUp).Row 频率=工作表(“参数”)。范围(“b7”) '删除除参数表之外的所有表 将ws设置为工作表 Application.DisplayAlerts=False 对于工作表中的每个ws 如果ws.Name“Parameters”和ws.Name“About”,那么ws.Delete 下一个 Application.DisplayAlerts=True “在所有的股票上循环 对于ticker=12至最后一行 stockTicker=工作表(“参数”)。范围($a$”&ticker) 如果stockTicker=“”,则 后藤下滴度 如果结束 Sheets.Add After:=工作表(Sheets.Count) 如果InStr(股票代码“:”)大于0,则 ActiveSheet.Name=Replace(股票代码“:”,“”) 其他的 ActiveSheet.Name=stockTicker 如果结束 单元格(1,1)=“股票报价”和股票报价器 调用下载股票报价(股票行情、工作表(“参数”).范围($b$5)、工作表(“参数”).范围($b$6”)、“$a$2”、频率) 列(“a:a”)。TextToColumns目标:=范围(“a1”)、数据类型:=xlDelimited_ TextQualifier:=xlDoubleQuote,continuedDelimiter:=False,Tab:=True_ 分号:=假,逗号:=真,空格:=假,其他:=假,字段信息:=数组(数组(1,1),数组(2,1),数组(3,1),数组(4,1),数组(5,1),数组(6,1),数组(7,1)) 如果InStr(股票代码“:”)大于0,则 stockTicker=替换(stockTicker,:,) 如果结束 表(股票代码)。列(“A:G”)。列宽=10 lastRow=工作表(stockTicker).UsedRange.Row-2+工作表(stockTicker).UsedRange.Rows.Count 如果lastRow<3,则 Application.DisplayAlerts=False 工作表(股票代码)。删除 numStockErrors=numStockErrors+1 错误列表股票代码 后藤下滴度 Application.DisplayAlerts=True 其他的 numStockSuccess=numStockSuccess+1 如果左(stockTicker,1)=“^”,则 成功列表替换(股票代码“^”、”),numStockSuccess 其他的 SuccessList股票行情器,numStockSuccess 如果结束 如果结束 Sheets(stockTicker).Sort.SortFields.Add关键字:=Range(“A3:A”&lastRow),SortOn:=xlSortOnValues,Order:=xlAscending,DataOption:=xlSortNormal 带工作表(stockTicker)。排序 .SetRange范围(“A2:G”和lastRow) .Header=xlYes .MatchCase=False .方向=xlTopToBottom .SortMethod=xl拼音 .申请 以 范围(“a3:a”和最后一行)。NumberFormat=“yyyy-mm-dd;” '删除最后一个空行,否则将在CSV底部获得,、、 工作表(stockTicker).行(lastRow+1&“:”&工作表(stockTicker).行.计数).删除 '从工作表中删除股票代码名称中的首字母^ 如果左(stockTicker,1)=“^”,则 ActiveSheet.Name=Replace(股票代码“^”和“) 其他的 ActiveSheet.Name=stockTicker 如果结束 '从工作表名称中删除股票代码名称中的连字符,否则排序错误 如果InStr(股票代码“-”)大于0,则 ActiveSheet.Name=Replace(股票代码“-”,“”) 如果结束 下一次滴定: 下一站 Application.DisplayAlerts=False 如果图纸(“参数”).Shapes(“WriteToCSVCheckBox”).ControlFormat.Value=xlOn,则 错误转到错误处理程序时: 呼叫CopyToCSV 如果结束 如果图纸(“参数”).Shapes(“CollateDataCheckBox”).ControlFormat.Value=xlOn,则 错误转到错误处理程序时: 调用数据 如果结束 错误处理程序: 工作表(“参数化
  Sub Test()

  Dim ws As Worksheet
  Dim qr As QueryTable
  Dim URL As String


  Set ws = Worksheets("Sheet1")

  Sheets("Sheet1").Cells.Clear
  URL = "https://finance.yahoo.com/quote/SPY/history?period1=1342681200&period2=1500447600&interval=1d&filter=history&frequency=1d"

  Set qr = ws.QueryTables.Add( _
      Connection:="URL;" & URL, _
      Destination:=Range("A1"))
      qr.RefreshStyle = xlOverwriteCells = True
      qr.BackgroundQuery = True
      qr.SaveData = True
      qr.Refresh BackgroundQuery = False


  End Sub
'Samir Khan
'simulationconsultant@gmail.com
'The latest version of this spreadsheet can be downloaded from http://investexcel.net/multiple-stock-quote-downloader-for-excel/
'Please link to http://investexcel.net if you like this spreadsheet


Sub DownloadStockQuotes(ByVal stockTicker As String, ByVal StartDate As Date, ByVal EndDate As Date, ByVal DestinationCell As String, ByVal freq As String)

Dim qurl As String
Dim StartMonth, StartDay, StartYear, EndMonth, EndDay, EndYear As String

qurl = "http://finance.google.com/finance/historical?q=" & stockTicker
qurl = qurl & "&startdate=" & MonthName(Month(StartDate), True) & _
       "+" & Day(StartDate) & "+" & Year(StartDate) & _
       "&enddate=" & MonthName(Month(EndDate), True) & _
       "+" & Day(EndDate) & "+" & Year(EndDate) & "&output=csv"

On Error GoTo ErrorHandler:

QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=Range(DestinationCell))
    .BackgroundQuery = True
    .TablesOnlyFromHTML = False
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With

ErrorHandler:

End Sub

Sub DownloadData()

Dim frequency As String
Dim numRows As Integer
Dim lastRow As Integer
Dim lastErrorRow As Integer
Dim lastSuccessRow As Integer
Dim stockTicker As String
Dim numStockErrors As Integer
Dim numStockSuccess As Integer

numStockErrors = 0
numStockSuccess = 0

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

lastErrorRow = ActiveSheet.Cells(Rows.Count, "J").End(xlUp).Row
lastSuccessRow = ActiveSheet.Cells(Rows.Count, "L").End(xlUp).Row

ClearErrorList lastErrorRow
ClearSuccessList lastSuccessRow

lastRow = ActiveSheet.Cells(Rows.Count, "a").End(xlUp).Row
frequency = Worksheets("Parameters").Range("b7")

'Delete all sheets apart from Parameters sheet
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
    If ws.Name <> "Parameters" And ws.Name <> "About" Then ws.Delete
Next

Application.DisplayAlerts = True

'Loop through all tickers
For ticker = 12 To lastRow

    stockTicker = Worksheets("Parameters").Range("$a$" & ticker)

    If stockTicker = "" Then
        GoTo NextIteration
    End If

    Sheets.Add After:=Sheets(Sheets.Count)

    If InStr(stockTicker, ":") > 0 Then
        ActiveSheet.Name = Replace(stockTicker, ":", "")
    Else
        ActiveSheet.Name = stockTicker
    End If

    Cells(1, 1) = "Stock Quotes for " & stockTicker
    Call DownloadStockQuotes(stockTicker, Worksheets("Parameters").Range("$b$5"), Worksheets("Parameters").Range("$b$6"), "$a$2", frequency)
    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))


    If InStr(stockTicker, ":") > 0 Then
        stockTicker = Replace(stockTicker, ":", "")
    End If

    Sheets(stockTicker).Columns("A:G").ColumnWidth = 10

    lastRow = Sheets(stockTicker).UsedRange.Row - 2 + Sheets(stockTicker).UsedRange.Rows.Count

    If lastRow < 3 Then
        Application.DisplayAlerts = False
        Sheets(stockTicker).Delete
        numStockErrors = numStockErrors + 1
        ErrorList stockTicker, numStockErrors
        GoTo NextIteration
        Application.DisplayAlerts = True
    Else
        numStockSuccess = numStockSuccess + 1
        If Left(stockTicker, 1) = "^" Then
            SuccessList Replace(stockTicker, "^", ""), numStockSuccess
        Else
            SuccessList stockTicker, numStockSuccess
        End If
    End If

    Sheets(stockTicker).Sort.SortFields.Add Key:=Range("A3:A" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With Sheets(stockTicker).Sort
        .SetRange Range("A2:G" & lastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

    Range("a3:a" & lastRow).NumberFormat = "yyyy-mm-dd;@"

    'Delete final blank row otherwise will get ,,,, at bottom of CSV
    Sheets(stockTicker).Rows(lastRow + 1 & ":" & Sheets(stockTicker).Rows.Count).Delete

    'Remove initial ^ in ticker names from Sheets
    If Left(stockTicker, 1) = "^" Then
        ActiveSheet.Name = Replace(stockTicker, "^", "")
    Else
        ActiveSheet.Name = stockTicker
    End If

    'Remove hyphens in ticker names from Sheet names, otherwise error in collation
    If InStr(stockTicker, "-") > 0 Then
        ActiveSheet.Name = Replace(stockTicker, "-", "")
    End If


NextIteration:
Next ticker

Application.DisplayAlerts = False

If Sheets("Parameters").Shapes("WriteToCSVCheckBox").ControlFormat.Value = xlOn Then
    On Error GoTo ErrorHandler:
    Call CopyToCSV
End If

If Sheets("Parameters").Shapes("CollateDataCheckBox").ControlFormat.Value = xlOn Then
    On Error GoTo ErrorHandler:
    Call CollateData
End If

ErrorHandler:

Worksheets("Parameters").Select

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

Worksheets("Parameters").Select
For Each C In ThisWorkbook.Connections
    C.Delete
Next

End Sub
Sub CollateData()

Dim ws As Worksheet
Dim i As Integer, first As Integer
Dim maxRow As Integer
Dim maxTickerWS As Worksheet

maxRow = 0
For Each ws In Worksheets
    If ws.Name <> "Parameters" Then
        If ws.UsedRange.Rows.Count > maxRow Then
            maxRow = ws.UsedRange.Rows.Count
            Set maxTickerWS = ws
        End If
    End If
Next

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Open"

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "High"

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Low"

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Close"

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Volume"

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Adjusted Close"

i = 1
maxTickerWS.Range("A2", "B" & maxRow).Copy Destination:=Sheets("Open").Cells(1, i)
Sheets("Open").Cells(1, i + 1) = maxTickerWS.Name

maxTickerWS.Range("A2", "a" & maxRow).Copy Destination:=Sheets("High").Cells(1, i)
maxTickerWS.Range("c2", "c" & maxRow).Copy Destination:=Sheets("High").Cells(1, i + 1)
Sheets("High").Cells(1, i + 1) = maxTickerWS.Name

maxTickerWS.Range("A2", "a" & maxRow).Copy Destination:=Sheets("Low").Cells(1, i)
maxTickerWS.Range("d2", "d" & maxRow).Copy Destination:=Sheets("Low").Cells(1, i + 1)
Sheets("Low").Cells(1, i + 1) = maxTickerWS.Name

maxTickerWS.Range("A2", "a" & maxRow).Copy Destination:=Sheets("Close").Cells(1, i)
maxTickerWS.Range("e2", "e" & maxRow).Copy Destination:=Sheets("Close").Cells(1, i + 1)
Sheets("Close").Cells(1, i + 1) = maxTickerWS.Name

maxTickerWS.Range("A2", "a" & maxRow).Copy Destination:=Sheets("Volume").Cells(1, i)
maxTickerWS.Range("f2", "f" & maxRow).Copy Destination:=Sheets("Volume").Cells(1, i + 1)
Sheets("Volume").Cells(1, i + 1) = maxTickerWS.Name

maxTickerWS.Range("A2", "a" & maxRow).Copy Destination:=Sheets("Adjusted Close").Cells(1, i)
maxTickerWS.Range("g2", "g" & maxRow).Copy Destination:=Sheets("Adjusted Close").Cells(1, i + 1)
Sheets("Adjusted Close").Cells(1, i + 1) = maxTickerWS.Name

i = i + 2

For Each ws In Worksheets

    If ws.Name <> "Parameters" And ws.Name <> "About" And ws.Name <> maxTickerWS.Name And ws.Name <> "Open" And ws.Name <> "High" And ws.Name <> "Low" And ws.Name <> "Close" And ws.Name <> "Volume" And ws.Name <> "Adjusted Close" Then

        Sheets("Open").Cells(1, i) = ws.Name
        Sheets("Open").Range(Sheets("Open").Cells(2, i), Sheets("Open").Cells(maxRow - 1, i)).Formula = _
        "=vlookup(A2," & ws.Name & "!A$2:G$" & maxRow & ",2,0)"

        Sheets("High").Cells(1, i) = ws.Name
        Sheets("High").Range(Sheets("High").Cells(2, i), Sheets("High").Cells(maxRow - 1, i)).Formula = _
        "=vlookup(A2," & ws.Name & "!A$2:G$" & maxRow & ",3,0)"

        Sheets("Low").Cells(1, i) = ws.Name
        Sheets("Low").Range(Sheets("Low").Cells(2, i), Sheets("Low").Cells(maxRow - 1, i)).Formula = _
        "=vlookup(A2," & ws.Name & "!A$2:G$" & maxRow & ",4,0)"

        Sheets("Close").Cells(1, i) = ws.Name
        Sheets("Close").Range(Sheets("Close").Cells(2, i), Sheets("Close").Cells(maxRow - 1, i)).Formula = _
        "=vlookup(A2," & ws.Name & "!A$2:G$" & maxRow & ",5,0)"

        Sheets("Volume").Cells(1, i) = ws.Name
        Sheets("Volume").Range(Sheets("Volume").Cells(2, i), Sheets("Volume").Cells(maxRow - 1, i)).Formula = _
        "=vlookup(A2," & ws.Name & "!A$2:G$" & maxRow & ",6,0)"

        Sheets("Adjusted Close").Cells(1, i) = ws.Name
        Sheets("Adjusted Close").Range(Sheets("Adjusted Close").Cells(2, i), Sheets("Adjusted Close").Cells(maxRow - 1, i)).Formula = _
        "=vlookup(A2," & ws.Name & "!A$2:G$" & maxRow & ",7,0)"

        i = i + 1

    End If
Next

On Error Resume Next

Sheets("Open").UsedRange.SpecialCells(xlFormulas, xlErrors).Clear
Sheets("Close").UsedRange.SpecialCells(xlFormulas, xlErrors).Clear
Sheets("High").UsedRange.SpecialCells(xlFormulas, xlErrors).Clear
Sheets("Low").UsedRange.SpecialCells(xlFormulas, xlErrors).Clear
Sheets("Volume").UsedRange.SpecialCells(xlFormulas, xlErrors).Clear
Sheets("Adjusted Close").UsedRange.SpecialCells(xlFormulas, xlErrors).Clear

On Error GoTo 0

Sheets("Open").Columns("A:A").EntireColumn.AutoFit
Sheets("High").Columns("A:A").EntireColumn.AutoFit
Sheets("Low").Columns("A:A").EntireColumn.AutoFit
Sheets("Close").Columns("A:A").EntireColumn.AutoFit
Sheets("Volume").Columns("A:A").EntireColumn.AutoFit
Sheets("Adjusted Close").Columns("A:A").EntireColumn.AutoFit
End Sub

Sub SuccessList(ByVal stockTicker As String, ByVal numStockSuccess As Integer)

Sheets("Parameters").Range("L" & 10 + numStockSuccess) = stockTicker

Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlDiagonalDown).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlDiagonalUp).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeLeft).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeTop).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeBottom).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeRight).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlInsideVertical).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlInsideHorizontal).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlDiagonalDown).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlDiagonalUp).LineStyle = xlNone

With Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With

Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlInsideVertical).LineStyle = xlNone
Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Borders(xlInsideHorizontal).LineStyle = xlNone

With Sheets("Parameters").Range("L10:L" & 10 + numStockSuccess).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent2
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With

End Sub

Sub ErrorList(ByVal stockTicker As String, ByVal numStockErrors As Integer)

Sheets("Parameters").Range("J" & 10 + numStockErrors) = stockTicker

Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlDiagonalDown).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlDiagonalUp).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeLeft).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeTop).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeBottom).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeRight).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlInsideVertical).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlInsideHorizontal).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlDiagonalDown).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlDiagonalUp).LineStyle = xlNone

With Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With
With Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With

Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlInsideVertical).LineStyle = xlNone
Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Borders(xlInsideHorizontal).LineStyle = xlNone

With Sheets("Parameters").Range("J10:J" & 10 + numStockErrors).Interior
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorAccent2
    .TintAndShade = 0.799981688894314
    .PatternTintAndShade = 0
End With

End Sub

Sub ClearErrorList(ByVal lastErrorRow As Integer)
If lastErrorRow > 10 Then
    Worksheets("Parameters").Range("J11:J" & lastErrorRow).Clear
    With Sheets("Parameters").Range("J10").Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Sheets("Parameters").Range("J10").Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Sheets("Parameters").Range("J10").Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Sheets("Parameters").Range("J10").Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
End If
End Sub

Sub ClearSuccessList(ByVal lastSuccessRow As Integer)
If lastSuccessRow > 10 Then
    Worksheets("Parameters").Range("L11:L" & lastSuccessRow).Clear
    With Sheets("Parameters").Range("L10").Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Sheets("Parameters").Range("L10").Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Sheets("Parameters").Range("L10").Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Sheets("Parameters").Range("L10").Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
End If
End Sub


Sub CopyToCSV()

Dim MyPath As String
Dim MyFileName As String

dateFrom = Worksheets("Parameters").Range("$b$5")
dateTo = Worksheets("Parameters").Range("$b$6")
frequency = Worksheets("Parameters").Range("$b$7")
MyPath = Worksheets("Parameters").Range("$b$8")

For Each ws In Worksheets
    If ws.Name <> "Parameters" And ws.Name <> "About" Then
        ticker = ws.Name
        MyFileName = ticker & " " & Format(dateFrom, "dd-mm-yyyy") & " - " & Format(dateTo, "dd-mm-yyyy") & " " & frequency
        If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
        If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
        Sheets(ticker).Copy
        With ActiveWorkbook
            .SaveAs Filename:= _
                    MyPath & MyFileName, _
                    FileFormat:=xlCSV, _
                    CreateBackup:=False
            .Close False
        End With
    End If
Next

End Sub
Sub DownloadStockQuotes()

    Dim qurl As String
    qurl = "http://finance.google.com/finance/historical?q=SPY&startdate=Jan+01+1970&enddate=Dec+31+2050&output=csv"

    Dim qt As QueryTable
    Set qt = ActiveSheet.QueryTables.Add(connection:="TEXT;" & qurl, Destination:=Range("b2"))

    With qt
        .Name = "Output"
        .FieldNames = True
        .RowNumbers = True
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 1252
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False

        .TextFileColumnDataTypes = Array(2)         ' This doesn't make any difference anymore

        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False

    End With
End Sub