Sub Import_Jsn()
Dim Bdd As ListObject, lg As Integer, Td As Variant, Lig As Long
Dim Rcd As Object, Rlst As Object, Elm As Object, i As Integer
Dim Fin As Boolean
Dim Url As String
Dim EnregStart As Long
Dim EnregPrec As Long
Dim UrlDataSet As String
Dim DataSet As String
On Error Resume Next
Set Bdd = Range("Ts_Siren").ListObject
If Bdd.ListRows.Count > 0 Then
For lg = 1 To Bdd.ListRows.Count
EnregStart = 0
EnregPrec = 0
Fin = False
While Not Fin
EnregStart = EnregPrec
'UrlDataSet = SIRENEV3 & DataSet & "/records?start=&rows=100&refine=siren%3A"
UrlDataSet = SIRENEV3 & DataSet & "/records?start=&rows=20&refine=siren%3A"
Url = Replace(UrlDataSet, "start=", "start=" & EnregStart)
'Set Rcd = HTML(SIRENEV3 & Bdd.DataBodyRange(lg, 1).Value)
Set Rcd = HTML(Url & Bdd.DataBodyRange(lg, 1).Value)
If Not Rcd Is Nothing Then
Set Rlst = VBA.CallByName(Rcd, "results", VbGet)
ReDim Td(1 To Rcd.total_count, 1 To 8)
'For i = 0 To Rcd.total_count - 1
i = 0
Do
Set Elm = VBA.CallByName(Rlst, i, VbGet)
Td(i + 1, 1) = Bdd.DataBodyRange(lg, 1).Value
Td(i + 1, 2) = Elm.siret
Td(i + 1, 3) = Elm.denominationunitelegale
Td(i + 1, 4) = Elm.enseigne1etablissement
Td(i + 1, 5) = Elm.numerovoieetablissement & " " & _
Elm.typevoieetablissement & " " & _
Elm.libellevoieetablissement
Td(i + 1, 6) = Elm.codepostaletablissement
Td(i + 1, 7) = Elm.libellecommuneetablissement
Td(i + 1, 8) = IIf(IsNull(Elm.datefermetureunitelegale), "OUI", "NON")
i = i + 1
'Next i
Loop Until i > Rcd.total_count And Not IsError(VBA.CallByName(Rlst, i, VbGet))
Lig = ActiveSheet.Cells(Rows.Count, "E").End(xlUp).Row + 1
ActiveSheet.Range("E" & Lig).Resize(UBound(Td, 1), UBound(Td, 2)) = Td
EnregPrec = EnregStart + i
If EnregPrec >= Rcd.total_count Then Fin = True
Else
Fin = True
End If
Wend
Next lg
End If
Exit Sub
End Sub