Gavin Harrison
New Member
- Joined
- May 2, 2017
- Messages
- 34
Hi.
Im new to the world of API's and working on a project at work where i need to extract data from an API and to paste this data into a worksheet. Ive looked at various videos etc and seem to be struggling so any help would be appreciated.
I have this code so far which gets the data from a sample API file.
What do i need to add on to get this data to sit in an excel worksheet within the same document.
Thanks
Im new to the world of API's and working on a project at work where i need to extract data from an API and to paste this data into a worksheet. Ive looked at various videos etc and seem to be struggling so any help would be appreciated.
I have this code so far which gets the data from a sample API file.
What do i need to add on to get this data to sit in an excel worksheet within the same document.
Thanks
VBA Code:
Sub APIcall()
Dim objRequest As Object
Dim strUrl As String
Dim blnAsync As Boolean
Dim strResponse As String
Dim json As Object
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
Set objRequest = CreateObject("MSXML2.XMLHTTP")
strUrl = "https://randomuser.me/api/"
blnAsync = True
With objRequest
.Open "GET", strUrl, blnAsync
.SetRequestHeader "Content-Type", "application/json"
.Send
Do While objRequest.readyState <> 4
DoEvents
Loop
strResponse = .ResponseText
End With
Debug.Print strResponse
Set json = JsonConverter.ParseJson(strResponse)
Debug.Print json
End Sub