OBJECTIVE
Pull in exchange rate data for various currencies.
APPROACH
- Select Active Sheet and copy currencies-to-be-converted into an array (e.g ["EUR", "GBP", "USD"]
- Open Browser and visit currency conversion website
- Loop through different currencies and extract currency conversion factors
- Append conversion factors to an array
- Repopulate excel with newest conversion factors
CODE
Sub retreiveCurrencies()
Dim ws As Worksheet
Dim locals() As Variant
Dim exchangeArray() As Variant
Dim i As Long
Dim IE As Object
'Select currencies to convert
Sheets("APPENDIX - CURRENCY CONVERTER").Activate
locals = Array(ActiveSheet.Range("B2:B15"))
'This should return locals = ["EUR", "GBP, "USD"]
'Prep Internet Explorer
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = False
Do While IE.Busy And Not IE.readyState = READYSTATE_COMPLETE
DoEvents
Loop
'Loop through currencies and retreive exchange rates. Paste rates into exchangeArray
For i = LBound(locals()) To UBound(locals())
IE.Navigate "http://www.usforex.com/currency-converter/" & locals(i) & "/usd/1.00/false"
exchange = IE.Document.GetElementById("converterToAmount").innerText
'exchangeArray = [] QUESTION: What should I add here to create an array of exchange rates?
Next i
'Paste exchange rate array into currency conversion column
ActiveSheet.Range("D2:D15") = exchangeArray()
End Sub
QUESTIONS/ISSUE(S)
- For line
IE.Navigate "http://www.usforex.com/currency-converter/" & locals(i) & "/usd/1.00/false"I receive a "Type Mismatch". Do I need to convertlocals()to text? - How do I loop through
IE.Document.GetElementById("converterToAmount").innerTextand append retrieved values to a new arrayexchangeArray()
NOTE: There may be many errors in this code. I am a VBA newbie and this is my attempt at a more complex script.