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):
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)
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)