I have a code in vba that when running shows error 438

Asked

Viewed 30 times

0

Sub buscacep()

Range("B3:D3").ClearContents
    
Set ie = CreateObject("InternetExplorer.application")
ie.navigate "https://www.achecep.com.br/"
ie.Visible = True


Do While ie.busy And ie.readystate <> "READYSTATE_COMPLETE"
DoEvents
Loop

ie.document.getElementByTagName("input")(0).Value = Cells(3, 2).Value

ie.document.getElementByClassName("botao")(0).Click

Do While ie.busy And ie.readystate <> "READYSTATE_COMPLETE"
DoEvents
Loop

End Sub

This is the code, but I can’t find the error. And when debugging, the line that shows error is:

ie.document.getElementByTagName("input")(0).Value = Cells(3, 2).Value

1 answer

0

Hello!

All right?

I believe you’ll laugh when you read this, but it wasn’t working because you missed an "s" in "getElementByTagName" and "getElementByTagName".

The correct is:

ie.document.getElementsByTagName("input")(0).Value = Cells(3, 2).Value

ie.document.getElementsByClassName("botao")(0).Click

By changing this, it worked normally.

Also, I don’t know how you insert data into the spreadsheet itself, but to test, I deactivated the line to clear the range ("B3:D3") and typed any real zip code, because without values in the cell, returned error as well.

Anything, let me know.

Browser other questions tagged

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