Here we show how to get data from Quandl, the online marketplace for financial, economic and alternative data.
We do this for two types of data: FX rates and OPEC oil prices.
Screenshots
Section titled “Screenshots”
FX Rates

OPEC Prices
VBA Module Code - FX Rates
Section titled “VBA Module Code - FX Rates”Sub Get_FXRates()Application.DisplayAlerts = False
'Define VariablesDim lastRow As IntegerDim Code, qurl As StringDim edate, sdate As Date
Code = Range("Code").Valueedate = Range("End_Date").Valuesdate = Range("Start_Date").Value
'Define Sourcequrl = "https://www.quandl.com/api/v3/datasets/BOE/" & Code & ".csv?" & "start_date=" & Year(sdate) & "-" & Month(sdate) & "-" & Day(sdate) & "&end_date=" & Year(edate) & "-" & Month(edate) & "-" & Day(edate) & "&api_key=YOUR_API_KEY"
'Clear PriorlastRow = Sheets("FX Rates").Cells(Rows.Count, "A").End(xlUp).RowSheets("FX Rates").Range(Cells(1, 1), Cells(lastRow, 2)).Clear
'Query TableActiveWorkbook.Worksheets("FX Rates").ActivateWith ActiveSheet.QueryTables.Add(Connection:="TEXT;" & qurl & "", Destination:=Range("$A$2")).Name = "Test".FieldNames = True.RowNumbers = False.FillAdjacentFormulas = False.PreserveFormatting = False.RefreshOnFileOpen = False.RefreshStyle = xlInsertDeleteCells.SavePassword = False.SaveData = True.AdjustColumnWidth = False.RefreshPeriod = 0.TextFilePromptOnRefresh = False.TextFilePlatform = 65001.TextFileStartRow = 1.TextFileParseType = xlDelimited.TextFileTextQualifier = xlTextQualifierDoubleQuote.TextFileConsecutiveDelimiter = False.TextFileTabDelimiter = True.TextFileSemicolonDelimiter = False.TextFileCommaDelimiter = True.TextFileSpaceDelimiter = False.TextFileColumnDataTypes = Array(1, 1, 9, 9).TextFileTrailingMinusNumbers = True.Refresh BackgroundQuery:=FalseEnd With
'Format Data Range("A2:B2").Select Selection.Font.Bold = True Columns("A:A").Select Selection.NumberFormat = "dd/mm/yyyy;@" lastRow = Sheets("FX Rates").Cells(Rows.Count, "A").End(xlUp).Row Range("A2:B" & lastRow).Select Application.CutCopyMode = False
'Remove Data connections and Query Tables Dim Cn As Variant For Each Cn In ThisWorkbook.Connections Cn.Delete Next Cn For Each Cn In ActiveSheet.QueryTables Cn.Delete Next Cn
'Table Formatting ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$2:$B$" & lastRow), , xlYes).Name = _ "FX_Rates" ActiveSheet.ListObjects("FX_Rates").TableStyle = "TableStyleMedium2" Range("A1").Select
End SubVBA Module Code - OPEC Prices
Section titled “VBA Module Code - OPEC Prices”Sub Get_OpecPrices()Application.DisplayAlerts = False
'Define VariablesDim lastRow As IntegerDim qurl As StringDim edate, sdate As Date
edate = Range("End_Date2").Valuesdate = Range("Start_Date2").Value
'Define Sourcequrl = "https://www.quandl.com/api/v3/datasets/OPEC/ORB.csv?" & "start_date=" & Year(sdate) & "-" & Month(sdate) & "-" & Day(sdate) & "&end_date=" & Year(edate) & "-" & Month(edate) & "-" & Day(edate) & "&api_key=YOUR_API_KEY"
'Clear PriorlastRow = Sheets("OPEC Prices").Cells(Rows.Count, "A").End(xlUp).RowSheets("OPEC Prices").Range(Cells(1, 1), Cells(lastRow, 2)).Clear
'Query TableActiveWorkbook.Worksheets("OPEC Prices").ActivateWith ActiveSheet.QueryTables.Add(Connection:="TEXT;" & qurl & "", Destination:=Range("$A$2")).Name = "Test".FieldNames = True.RowNumbers = False.FillAdjacentFormulas = False.PreserveFormatting = False.RefreshOnFileOpen = False.RefreshStyle = xlInsertDeleteCells.SavePassword = False.SaveData = True.AdjustColumnWidth = False.RefreshPeriod = 0.TextFilePromptOnRefresh = False.TextFilePlatform = 65001.TextFileStartRow = 1.TextFileParseType = xlDelimited.TextFileTextQualifier = xlTextQualifierDoubleQuote.TextFileConsecutiveDelimiter = False.TextFileTabDelimiter = True.TextFileSemicolonDelimiter = False.TextFileCommaDelimiter = True.TextFileSpaceDelimiter = False.TextFileColumnDataTypes = Array(1, 1, 9, 9).TextFileTrailingMinusNumbers = True.Refresh BackgroundQuery:=FalseEnd With
'Format Data Range("A2:B2").Select Selection.Font.Bold = True Columns("A:A").Select Selection.NumberFormat = "dd/mm/yyyy;@" Range("B2").Select ActiveCell.FormulaR1C1 = "Value ($/bbl)" Range("B3").Select Columns("B:B").EntireColumn.AutoFit
lastRow = Sheets("OPEC Prices").Cells(Rows.Count, "A").End(xlUp).Row Range("A2:B" & lastRow).Select Application.CutCopyMode = False
'Remove Data connections and Query Tables Dim Cn As Variant For Each Cn In ThisWorkbook.Connections Cn.Delete Next Cn For Each Cn In ActiveSheet.QueryTables Cn.Delete Next Cn
'Table Formatting ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$2:$B$" & lastRow), , xlYes).Name = _ "Opec_Prices" ActiveSheet.ListObjects("Opec_Prices").TableStyle = "TableStyleMedium6" Range("A1").Select
End SubCheck API Key
Section titled “Check API Key”Download
Section titled “Download”The full file can be downloaded here: