1
The code below works perfect to return data by Excel with Web Scraping. I installed in the file the module VBA-JSON-2.3.1 - module name Jsonconverter.bas. I enabled the Microsoft Scripting Runtime reference. Return all brands, brands and models, etc. The error happens when I try to return the current value of a specific brand, model and year. Gives incompatible types error in this line, er if comment the line also gives error in the others.:
Planilha4.Cells(I, 1).Value = Item("referencia")
I believe it is because the return comes this way, no brackets at the beginning and at the end:
{"referencia": "maio de 2019", "fipe_codigo": "001267-0", "name": "Palio 1.0 ECONOMY Fire Flex 8V 4p", "combustivel": "Gasolina", "marca": "Fiat", "ano_modelo": "2013", "preco": "R$ 22.533,00", "key": "palio-2013", "time": 0.0, "veiculo": "Palio 1.0 ECONOMY Fire Flex 8V 4p", "id": "2013"}
I can’t seem to solve the problem. Below is the complete code.
Sub RetornaPrecoMarcaCarroModeloAno()
    Dim http        As Object
    Dim JSON        As Object
    Dim I           As Integer
    Dim Item        As Variant
    Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "GET", "http://fipeapi.appspot.com/api/1/carros/veiculo/21/4828/2013-1.json", False
    http.Send
    Set JSON = ParseJson(http.responseText)
    I = 2
    For Each Item In JSON
        Planilha4.Cells(I, 1).Value = Item("referencia")
        Planilha4.Cells(I, 2).Value = Item("fipe_codigo")
        Planilha4.Cells(I, 3).Value = Item("name")
        Planilha4.Cells(I, 4).Value = Item("combustivel")
        Planilha4.Cells(I, 5).Value = Item("marca")
        Planilha4.Cells(I, 6).Value = Item("ano_modelo")
        Planilha4.Cells(I, 7).Value = Item("preco")
        Planilha4.Cells(I, 8).Value = Item("key")
        Planilha4.Cells(I, 9).Value = Item("veiculo")
        Planilha4.Cells(I, 10).Value = Item("id")
        I = I + 1
    Next
    MsgBox ("complete")
    Set http = Nothing
    Set JSON = Nothing
End Sub