ZIP code search via VBA programming

Asked

Viewed 201 times

3

I am developing a solution and the need to add the CEP research has arisen. In return I would like to get the address based on the CEP informed. I intend to use this search to fill out an automatic address after informing the ZIP code.

I started writing the code below but stopped at 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 gives as unregistered zip code!

1 answer

4


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

"http://republicavirtual.com.br/web_cep.php?cep="
  • Poxa... That’s right! Thank you very much for your help friend!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.