Estou recebendo o erro abaixo e não sei como consertar.
Quando aperto F8:
Erro em tempo de execução ‘91’:
A variável do objeto ou a variavel do bloco ‘With’ não foi deficinida
Quando clico no botão para excutar:
Erro em tempo de execução ‘424’:
O objeto é obrigatório.
Vou postar meu codigo abaixo.
Private Sub btExecuta_Click()
Application.ScreenUpdating = False
Dim vErro As String
Dim IELocation As String
Dim W As Worksheet
Dim Resultado(1 To 15) As String
Dim vNome As String
Dim vDados As String
Dim vSituacao As String
Dim Ie As Object
Dim UltCel As Range
Dim A As Integer
Dim col As Integer
Dim ln As Long
Set W = consult
W.Range("A2").Select
W.Range("B2:D1000").Clear
Set Ie = CreateObject("InternetExplorer.Application")
Set UltCel = W.Cells(W.Rows.Count, 1).End(xlUp)
With Ie
.navigate "https://www.situacao-cadastral.com/"
.Visible = True
End With
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
Do While Ie.busy
Loop
ln = 2
col = 1
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
Do While ln <= UltCel.Row
Ie.Document.getelementsbyid("doc").Value = W.Cells(ln, col)
Ie.Document.getelementsbyid("Consultar").Click
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
On Error Resume Next
vErro = Ie.Document.getelementsbyid("mensagem").innertext
On Error GoTo 0
If vErro = "#Erro: Tente novamente!" Then
Ie.Document.getelementsbyid("consultar").Click
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 5)
ElseIf vErro = " Informe um termo válido! " Then
W.Cells(ln, col + 1).Value = "'" & vErro
Else
vErro = vbNullString
End If
Do While Ie.busy
Loop
If vErro = vbNullString Then
vNome = Ie.Document.getelementsbyclassname("dados nome")(0).innertext
vDados = Ie.Document.getelementsbyclassname("dados texto")(0).innertext
vSituacao = Ie.Document.getelementsbyclassname("dados situacao")(0).innertext
W.Cells(ln, col + 1) = vNome
W.Cells(ln, col + 2) = vSituacao
W.Cells(ln, col + 3) = vDados
vNome = vbNullString
vDados = vbNullString
vSituacao = vbNullString
End If
ln = ln + 1
Loop
Ie.Quit
W.UsedRange.EntireColumn.AutoFit
Application.ScreenUpdating = True
DoEvents
MsgBox "Consulta realizada com sucesso!"
Application.ScreenUpdating = True
End Sub