Web Scraping IMF Data via Excel VBA

fatony

New Member
Joined
Sep 9, 2016
Messages
2
Hi!

I am trying to find a way to web scrape data from the IMF DataBase website. I want to let Excel full automatically download the Data i have already chosen by exact link and present it as a table.

I have made it already work on the FRED site (St. Louis Federal Reserve Economic Data) by this code (Example: Effective Federal Funds Rate):

Code:
Sub GetMacroData_EFFR()

Dim ws As Worksheet: Set ws = Worksheets("Effective Federal Funds Rate")


Dim strURLEFFR As String
    strURLEFFR = ws.[apiURL3]


Dim httpReq As New WinHttpRequest
    httpReq.Open "GET", strURLEFFR, False
    httpReq.Send


Dim strResp As String
    strResp = httpReq.ResponseText


Dim xmlSheet As New MSXML2.DOMDocument60
    If Not xmlSheet.LoadXML(strResp) Then
        MsgBox "Ladefehler. Das Herunterladen der neuen Daten scheint im Moment nicht zu funktionieren. (Fehler 0)" 'Fehler 0: API-Key, Status FRED, URL, XML Version, etc. überprüfen
    End If


Dim xNodeList As MSXML2.IXMLDOMNodeList
    Set xNodeList = xmlSheet.getElementsByTagName("observations")


Dim xNode As MSXML2.IXMLDOMNode
    Set xNode = xNodeList.Item(0)


Dim obsEFFRAtt1 As MSXML2.IXMLDOMAttribute
Dim obsEFFRAtt2 As MSXML2.IXMLDOMAttribute


Dim xChild As MSXML2.IXMLDOMNode


Dim intRow As Integer
    intRow = 2


Dim strCol1 As String
    strCol1 = "A"


Dim strCol2 As String
    strCol2 = "B"


Dim dtValue As Date
Dim dblRate As Double
Dim strVal As String


For Each xChild In xNode.ChildNodes
    Set obsEFFRAtt1 = xChild.Attributes.getNamedItem("date")
    Set obsEFFRAtt2 = xChild.Attributes.getNamedItem("value")
    strVal = Trim(obsEFFRAtt2.Text)
    If strVal = "." Then
        ws.Cells(intRow, 2) = ""
    Else
        ws.Cells(intRow, 2) = Format(strVal / 10000, "0.00%")
    End If
    ws.Cells(intRow, 1) = CDate(Trim(obsEFFRAtt1.Text))
    intRow = intRow + 1
Next xChild


Set httpReq = Nothing
Set xmlSheet = Nothing




End Sub

This worked really well. But i have a really hard time to find a solution for the IMF Site. I cannot find any API Keys or something like that to get the targeted data i want.
Do you know how i can get the data by VBA? For example: "Reserves" OR "Current Account". (Both as series data)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top