Get information from API using VBA and Update the Retrieved information in the column

RajG

New Member
Joined
May 4, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Dear Expert,

I hope all are doing well.

I have a requirement to retrieve the API data and the retrieved data will be displayed in an Excel cell. So, I successfully retrieved data from the API. But, I wasn't able to display the retrieved data in an Excel cell.

Can you please help me with this.

I have attached the screenshot for your reference.

I am using the below code to get the API data via VBA
1.3.png
code.

Private Sub CommandButton1_Click()

Dim JsonObject As Object
Dim objRequest As Object
Dim strUrl As String
Dim blnAsync As Boolean
Dim strResponse As String

Dim ws As Worksheet: Set ws = Worksheets("Sheet1")
Set objRequest = CreateObject("MSXML2.XMLHTTP")
strUrl = "https://dummyjson.com/carts"
'strUrl = ws.[APIUrl]
blnAsync = True
With objRequest
.Open "GET", strUrl, blnAsync
.setRequestHeader "Content-Type", "application/json"
'.setRequestHeader "Authorization", ws.[C7] & token
.Send
'Getting response from APIs
While objRequest.readyState <> 4
DoEvents
Wend
'API Response stored in var (strResponse)
strResponse = .responseText
End With
MsgBox (strResponse) 'Response will display in Popup box
'Range("P10").Value = strResponse 'Response will display in Sheet Column P10
'Debug.Print strResponse 'Response will display in Immediate window(VBA)

End Sub



1.1.png

1.2.png
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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