Sub BuscarPolizaAvanzada() Dim criterio As String Dim tipo As String Dim url As String Dim http As Object Dim response As String Dim fila As Integer criterio = Range("C12").Value If criterio = "" Then MsgBox "Ingresa criterio en C12", 48 Exit Sub End If tipo = Range("C11").Value If tipo = "" Then tipo = "numero_poliza" Range("A15:I100").ClearContents Range("A15").Value = "ID" Range("B15").Value = "Nombre" Range("C15").Value = "RUT" Range("D15").Value = "Telefono" Range("E15").Value = "Poliza" Range("F15").Value = "Compania" Range("G15").Value = "Monto" Range("H15").Value = "Deducible" Range("I15").Value = "Patente" With Range("A15:I15") .Font.Bold = True .Interior.Color = RGB(102, 126, 234) .Font.Color = RGB(255, 255, 255) End With url = "https://segurosrss.cl/buscar_poliza.php?q=" & URLEncode(criterio) & "&tipo=" & tipo Set http = CreateObject("MSXML2.XMLHTTP") http.Open "GET", url, False http.Send If http.Status = 200 Then response = http.responseText If InStr(response, "datos") > 0 Then fila = 16 Dim i As Integer i = 1 Do While InStr(response, "nombreCliente") > 0 And fila < 35 Dim id As String, nombre As String, rut As String, tel As String Dim poliza As String, compa As String, monto As String, ded As String, pat As String id = ExtractField(response, "id") nombre = ExtractField(response, "nombreCliente") rut = ExtractField(response, "rutCliente") tel = ExtractField(response, "telefono") poliza = ExtractField(response, "nPoliza") compa = ExtractField(response, "compania") monto = ExtractField(response, "montoAsegurado") ded = ExtractField(response, "deducible") pat = ExtractField(response, "patente") If id <> "" Then Range("A" & fila).Value = id Range("B" & fila).Value = nombre Range("C" & fila).Value = rut Range("D" & fila).Value = tel Range("E" & fila).Value = poliza Range("F" & fila).Value = compa Range("G" & fila).Value = monto Range("H" & fila).Value = ded Range("I" & fila).Value = pat fila = fila + 1 response = Mid(response, InStr(response, "nombreCliente") + 20) Else Exit Do End If Loop If fila > 16 Then MsgBox "Se encontraron " & (fila - 16) & " poliza(s)", 64 Else MsgBox "No hay resultados", 48 End If Else MsgBox "No se encontraron polizas", 48 End If Else MsgBox "Error: " & http.Status, 16 End If Set http = Nothing End Sub Function ExtractField(jsonStr As String, fieldName As String) As String Dim start As Integer Dim finish As Integer Dim quote As String Dim field As String quote = Chr(34) field = quote & fieldName & quote & ":" start = InStr(jsonStr, field) If start = 0 Then ExtractField = "" Exit Function End If start = start + Len(field) If Mid(jsonStr, start, 1) = quote Then start = start + 1 finish = InStr(start, jsonStr, quote) ExtractField = Mid(jsonStr, start, finish - start) Else finish = InStr(start, jsonStr, ",") If finish = 0 Then finish = InStr(start, jsonStr, "}") ExtractField = Trim(Mid(jsonStr, start, finish - start)) End If End Function