Last active
May 30, 2021 02:59
-
-
Save tonicanada/93a04b9e38463bd7f45a61b98f6ccefd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub getUsers() | |
Dim req As MSXML2.ServerXMLHTTP60 | |
Dim Parsed As Collection | |
Dim i As Integer | |
Set req = New MSXML2.ServerXMLHTTP60 | |
api_url = "https://jsonplaceholder.typicode.com/users" | |
req.Open "GET", api_url, False | |
'If credentials are required use: | |
'req.setRequestHeader "Authorization", "token 7a7b519704cc560:41aa8696c1d2a5d" | |
req.send | |
Set Parsed = JsonConverter.ParseJson(req.responseText) | |
'Setting the header | |
Worksheets("Sheet1").Cells(1, "A").Value = "id" | |
Worksheets("Sheet1").Cells(1, "B").Value = "name" | |
Worksheets("Sheet1").Cells(1, "C").Value = "email" | |
Worksheets("Sheet1").Cells(1, "D").Value = "address_street" | |
Worksheets("Sheet1").Cells(1, "E").Value = "address_suite" | |
Worksheets("Sheet1").Cells(1, "F").Value = "address_city" | |
Worksheets("Sheet1").Cells(1, "G").Value = "address_zipcode" | |
Worksheets("Sheet1").Cells(1, "H").Value = "address_geo_lat" | |
Worksheets("Sheet1").Cells(1, "I").Value = "address_geo_lng" | |
Worksheets("Sheet1").Cells(1, "J").Value = "phone" | |
Worksheets("Sheet1").Cells(1, "K").Value = "website" | |
Worksheets("Sheet1").Cells(1, "L").Value = "company_name" | |
Worksheets("Sheet1").Cells(1, "M").Value = "company_catchPhrase" | |
Worksheets("Sheet1").Cells(1, "N").Value = "company_bs" | |
Dim Value As Dictionary | |
i = 2 | |
For Each Value In Parsed | |
Worksheets("Sheet1").Cells(i, "A").Value = Value("id") | |
Worksheets("Sheet1").Cells(i, "B").Value = Value("name") | |
Worksheets("Sheet1").Cells(i, "C").Value = Value("email") | |
Worksheets("Sheet1").Cells(i, "D").Value = Value("address")("street") | |
Worksheets("Sheet1").Cells(i, "F").Value = Value("address")("suite") | |
Worksheets("Sheet1").Cells(i, "G").Value = Value("address")("city") | |
Worksheets("Sheet1").Cells(i, "H").Value = Value("address")("zipcode") | |
Worksheets("Sheet1").Cells(i, "I").Value = Value("address")("geo")("lat") | |
Worksheets("Sheet1").Cells(i, "J").Value = Value("address")("geo")("lng") | |
Worksheets("Sheet1").Cells(i, "K").Value = Value("phone") | |
Worksheets("Sheet1").Cells(i, "L").Value = Value("website") | |
Worksheets("Sheet1").Cells(i, "M").Value = Value("company")("name") | |
Worksheets("Sheet1").Cells(i, "N").Value = Value("company")("catchPhrase") | |
Worksheets("Sheet1").Cells(i, "N").Value = Value("company")("bs") | |
i = i + 1 | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment