BLISS LOGIC ACCOUNTANTS
  • Home
  • About
  • Contact
  • Blog
  • PRICING

INSIGHTS & IDEAS

Excel VBA To Read API

14/7/2023

0 Comments

 
​Sub FWAPI()

' ---------------------------------------------------------------------------------------------------------------------------
'   References that are required for the Excel Objects:
'       1) Microsoft WINHTTP Services, Version 5.1
'       2) Microsoft Scripting Runtime
'       3) Microsoft XML, v3
'       4) Microsoft HTML Object Library
' ---------------------------------------------------------------------------------------------------------------------------


    Dim request As New WinHttpRequest
    Dim weburl  As String
    Dim ws      As Worksheet
    Dim i       As Integer
    
    
    weburl = ""
    Set ws = ActiveSheet
    
    
    request.Open "Get", weburl
    request.Send
    
    If request.Status <> 200 Then
        MsgBox request.ResponseText
        Exit Sub
    End If
    
    Dim response As Object
    Set response = request.ResponseText
    
    '   ACCESS THE DATA
    
    Dim countries As Collection
    Set countries = response("country")
    
    Dim country As Dictionary
    
    i = 2
    
    For Each country In countries
        ws.Cells(i, 1).Value = country("country_id")
        ws.Cells(i, 2).Value = country("Probability")
    Next country
    
    
    
End Sub
0 Comments



Leave a Reply.

Site powered by Weebly. Managed by SiteGround
  • Home
  • About
  • Contact
  • Blog
  • PRICING