Private Sub buscacep()
On Error GoTo TratarErro
If Len(TextCEP) < 8 Then
MsgBox "CEP inválido, pois tem menos de 8 numeros", vbExclamation, "Avisso"
Exit Sub
End If
If TextCEP.Text <> "" Then
Range("cep!a1:h1").Clear
TextENDERECO = Empty
TextBAIRRO = Empty
ComboCIDADE = Empty
ComboUF = Empty
ActiveWorkbook.XmlImport URL:= _
"http://republicavirtual.com.br/web_cep.php?cep=" & TextCEP, ImportMap:= _
Nothing, Overwrite:=False, Destination:=Range("cep!$b$1")
TextENDERECO = VBA.UCase(Range("g1") & " " & Range("cep!h1"))
TextBAIRRO = VBA.UCase(Range("cep!f1"))
ComboCIDADE = VBA.UCase(Range("cep!e1"))
ComboUF = VBA.UCase(Range("cep!d1"))
'Me.Label6.Caption = "CEP procurado: " & vbNewLine & TextCEP.Text
'Me.Label6.Font.Bold = True
'TextBoxCep = Empty
End If
Calculate
TextCEP.SetFocus
SAIR:
Exit Sub
TratarErro:
MsgBox "CEP não cadastrado! " & Err.Description, vbCritical, Err.HelpFile
GoTo SAIR
Resume
'CommandButton9.Enabled = False
'CommandButton2.Enabled = False
'CommandButton6.Enabled = False
'CommandButton7.Enabled = False
'CommandButton8.Enabled = False
End Sub
Postado : 10/10/2015 1:10 pm