15

Download Historical Forex Data into Excel

This Excel spreadsheet downloads historical Forex data from the Internet, specifically the daily bid rates.

You simply enter two three-letter currency symbols, two dates, and click a button.

The spreadsheet will then connect to a remote website, and download daily bid rates (using some clever VBA).  The Forex data is imported into a sheet called “Data”.

Forex data imported into Excel

Now you can analyze and plot the forex data using all of Excel’s functionality. As an example, the spreadsheet plots the exchange rate data.  If you wanted, you could easily add Bollinger Bands to the plot.

I’ve password-protected the VBA module in the spreadsheet (I’m heavily modifying it for a future post), but if you want the password then let me know.

This is free Forex data that we’re downloading, and in no way shape or form compares with paid services.  Using the VBA programming principles used in the spreadsheet, you can easily use other tools, like Access databases, instead of Excel.

You may also be interested in this spreadsheet which downloads historical stock prices from Yahoo straight into Excel.

The spreadsheet is in Excel 97-2003 format, although I’ve only tested it in Excel 2010.

Update 29th July 2011: I’ve removed the password. Enjoy, and please come back and let me know what cool Forex applications you’ve made with it.

Download Excel Spreadsheet for automatically importing forex data from the Internet


15 Responses to "Download Historical Forex Data into Excel"

  1. Brent says:

    I am interested in working this code into an existing workbook I have made. This looks like an awesome tool and will do most of what I need it to do. How can I go about getting that password for the VBA code though so I can validate a few things?

    Thanks

  2. kristers says:

    Hi, I am really interested in the code,
    im having a few problems getting my workbook to do the same thing but with stock data.

  3. Sam says:

    @Brent and @kristers: I've removed the password from the spreadsheet (just download it again). Let me know what you super cool applications you come up with!

  4. Alberto says:

    Hi

    It looks like a terrific tool to use with excell. However, I opened the link to the spread sheet and try just to chage dates but excell won’t update because “the macro is either not available in the work book or may be disabled”

    Any suggestion?

    thx

    A

    • Samir says:

      I’ve just tried the spreadsheet in Excel 2010 and it works perfectly for me.

      When you loaded the spreadsheet in Excel, did you give the macro permission to run?

  5. Chris says:

    How do you modify the code so that you can query more than one “To Currency” at a time? So, suppose you want to get the FX rates for the conversion from GBP to up to 10 different currencies at the same time rather than changing the “To Currency and re-running over and over?

  6. Jim says:

    I tried the worksheet. I get an error

    “Compile Error: Variable not defined” on this line

    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

    This item is highlited: xlSortOnValues

  7. Pat says:

    I tried to run this on my WinXP Excel 2003
    and i had same error as Jim got,
    “Compile Error: Variable not defined”
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

  8. Brian says:

    Hi,
    I found your code very useful and have embedded it into one of my sheets. I would suggest updating the connection on each refresh rather than creating a new one as all of the connections will be refreshed on open unless this property is turned off on creation. The following code will achieve this:
    Dim FX_table As QueryTable
    Set FX_table = Sheets(strShtName).QueryTables(1)
    FX_table.Connection = “URL;” & str
    FX_table.Refresh

    Another approach would be to delete all existing connections before adding a new one:

    Public Sub RemoveQueries(shtName As String)
    Dim ws As Worksheet
    Dim qt As QueryTable
    Set ws = Sheets(shtName)
    For Each qt In ws.QueryTables
    qt.Delete
    Next qt
    End Sub

  9. Lance says:

    It is possible to modify to show the open, high, low, and close?

    Thanks (in advance),
    Lance

  10. Thomas says:

    Hi, works fantastic for me. I only had a problem using it on a german Excel version as the decimal separator was not correctly recognized. This could be overcome letting Excel know which character to recognize as the decimal separator. Maybe you could include it in your version to help other users who maybe jump into the same problem:

    Sheets(“Data”).Range(“a5″).CurrentRegion.TextToColumns Destination:=Sheets(“Data”).Range(“a5″), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, other:=True, OtherChar _
    :=”,”, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
    1), Array(6, 1)), DecimalSeparator:=”.”, ThousandsSeparator:=”‘”, _
    TrailingMinusNumbers:=True

  11. Leo says:

    Thomas, your solution for “non-US” Windows works great.
    Thanks a lot, you saved me plenty of time.

  12. joe002 says:

    Thanks a lot for this very useful tool!
    Just a remark on my side: you first set all calculations to manual and I personally prefer having them automatic, so I just added the following at the end of the GetData() macro:

    Application.Calculation = xlCalculationAutomatic

    Thanks again!

Leave a Reply

Submit Comment
What is 10 + 3 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)
© 2013 Invest Excel. All rights reserved. XHTML / CSS Valid.

Facebook