Runtime Error 438: Object does not accept property or Methods

Asked

Viewed 143 times

1

I’m adapting VBA code for scraping, but I’m getting this message when it comes to sending the data to the Login form.

Runtime Error 438: Object does not accept property or Methods

Public Sub VBA_extrair()
     Dim wb              As Workbook:        Set wb = ThisWorkbook
     Dim wsParam         As Worksheet:       Set wsParam = wb.Worksheets("Param")
     Dim IE              As Object:          Set IE = New InternetExplorer.Application
     Dim stUsuario       As String:          stUsuario = wsParam.Range("A2")
     Dim stSenha         As String:          stSenha = wsParam.Range("B2")
     With IE
          .Visible = True
          .navigate "https://www.canalcliente.com.br/portal/canal_cliente/index.htm"
          While IE.Busy Or IE.readyState <> 4: Wend
               With .document
                    .getElementById("txtUsuario").Value = username
                    .getElementById("txtSenha").Value = password
                    .getElementById("btnEntrar").Click
               End With
          While IE.Busy Or IE.readyState <> 4: Wend
     End With
     Set IE = Nothing
End Sub
  • Error happens exactly on which line?

  • OK! I learn fast.

  • The error appeared from . getElementById("txtUsuario"). Value = username, but the Augusto Vasques solution solved.

1 answer

1


On the page you want to access there is an iframe with the id "iframe1"

iframe

In your code where you are accessing the "Document" object you should consider that there is an iframe, the login elements are in iframe.

You’ll need to access the main Document > access iframe > access iframe Document, this way:

With .Document.frames.Item("iframe1").Document

Browser other questions tagged

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