CEP Search via VBA Programming

2

I am developing a solution and there is a need to add zip code search. In return I would like to get the address based on the CEP informed. I want to use this search to fill in the auto-address after I enter the zip code.

I started writing the code below but I stopped it.

Sub lsPesquisaCEP(ByVal sCEP As String)
    On Error GoTo TratarErro

    Range("Consulta!a1:H1").Clear

    If sCEP <> "" Then
        With ActiveWorkbook.XmlMaps("webservicecep_Mapa")
            .ShowImportExportValidationErrors = False
            .AdjustColumnWidth = True
            .PreserveColumnFilter = False
            .PreserveNumberFormatting = False
            .AppendOnImport = False
        End With
        ActiveWorkbook.XmlImport URL:= _
            "http:/republicavirtual.com.br/web_cep.php?cep=" & sCEP, ImportMap:= _
            Nothing, Overwrite:=False, Destination:=Range("Consulta!$a$1")


    End If

    Calculate

Sair:
    Exit Sub
TratarErro:
    MsgBox "CEP não cadastrado!"
    GoTo Sair
    Resume
End Sub

Always give as a zip code not registered!

    
asked by anonymous 07.08.2018 / 21:04

1 answer

3

When you enter the URL, a "/" is followed after "http:"

"http://republicavirtual.com.br/web_cep.php?cep="
    
07.08.2018 / 21:05