I am trying to convert a json api to excel table. I tried different parsing methods but currently using VBA-JSON (similar to VB-JSON but faster parsing). So far I got it to
It is faster to write all of the values at once then to do it cell by cell. Also you may have secondary event firing so disabling events may help with performance. If performance is still poor with the below code the problem is with the performance of JsonConverter.
Dim ItemCount As Integer
Dim items() As Variant
Function httpresp(URL As String) As String
Dim x As Object: Set x = CreateObject("MSXML2.XMLHTTP")
x.Open "GET", URL, False
x.send
httpresp = x.responseText
End Function
Private Sub btnLoad_Click()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim URL As String: URL = "https://www.gw2shinies.com/api/json/item/tp"
Dim DecJSON As Object: Set DecJSON = JsonConverter.ParseJson(httpresp(URL))
ItemCount = DecJSON.Count
ReDim items(1 To ItemCount, 1 To 1)
Range("A2:S25000").Clear 'clear range
Dim test As Variant
For i = 1 To ItemCount
items(i, 1) = DecJSON(i)("item_id")
'Cells(i + 1, 1).Value = DecJSON(i)("item_id")
Next i
Range(Range("A2"), Range("A2").Offset(ItemCount)).Value = items
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub