LISTING OF CURRENCY

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

LISTING OF CURRENCY

Post by sal21 »

I need to get day by day a currency value from an official site or download a txt from site...

i need:
ISO
UIC
Value (in Euro)
Name of currency

And insert the related value in a Access table.

Tks for suggestion

User avatar
bjsatola
NewLounger
Posts: 22
Joined: 24 Jul 2013, 17:55
Location: Worldly

Re: LISTING OF CURRENCY

Post by bjsatola »

Try playing with this. You can just modify the url string via the 'from' and 'date' fields according to the site.

Code: Select all

Sub ImportCurrency()
    IExplorerQueryTable "http://www.xe.com/currencytables/?from=USD&date=2014-10-24"
End Sub

Code: Select all

Sub IExplorerQueryTable(FullPathURL As String, Optional OutputToRange As Excel.Range)
'// Copies information from the 'FullPathURL' into 'OutputToRange'.
'// If 'OutputToRange' is not defined, a new worksheet is added to the end for output.

    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet
    
    '// Define output range
    If OutputToRange Is Nothing Then '// create definition
        Set wb = ThisWorkbook
        wb.Worksheets.Add After:=wb.Worksheets(wb.Worksheets.Count)
        Set ws = ActiveSheet
        Set OutputToRange = ActiveSheet.Range("A1")
    Else
        Set ws = OutputToRange.Worksheet
        ws.Cells.Clear
    End If

    '// Query Internet Source
    '// Output to Excel
    With Sheets(ws.Index).QueryTables.Add(Connection:="URL;" & FullPathURL, Destination:=OutputToRange)
        .BackgroundQuery = True
        .TablesOnlyFromHTML = False
        .Refresh BackgroundQuery:=False
        .SaveData = True
    End With

End Sub
You could, for instance, make the output sheet invisible. This way the results will update to the same range everyday (as long as the currencies listed on the site do not change).