Run-time error '424': Object Required IE.Document.GetElementById

后端 未结 2 757
时光取名叫无心
时光取名叫无心 2020-12-12 04:28

I\'m trying to auto-complete a form on a website with values of an excel file.

Sub CommandButton1_Click()
Dim IE As Object
Dim objElement As Object
Dim objCo         


        
相关标签:
2条回答
  • 2020-12-12 04:41

    Use a timed loop for element to be present

    Option Explicit
    'VBE > Tools > References:
    ' Microsoft Internet Controls
    '
    Public Sub CommandButton1_Click()
        Dim ie As New InternetExplorer, t As Date, ele As Object
        Const MAX_WAIT_SEC As Long = 10
    
    
        With ie
            .Visible = True
            .Navigate2 "https://www.ryanair.com/be/nl/check-in"
    
            While .Busy Or .readyState < 4: DoEvents: Wend
            t = Timer
            Do
                On Error Resume Next
                Set ele = .document.getElementById("username")
                On Error GoTo 0
                If Timer - t > MAX_WAIT_SEC Then Exit Do
            Loop While ele Is Nothing
    
            If ele Is Nothing Then Exit Sub
    
            ele.Value = "resa@connections.be"
    
            Stop
            .Quit
        End With
    End Sub
    
    0 讨论(0)
  • 2020-12-12 04:50

    Thank you for the quick answer! I just made small changes, as I received an error and I work with a button. It works like a charm now!

    Public Sub CommandButton1_Click()
        Dim ie As New InternetExplorer, t As Date, ele As Object
        Const MAX_WAIT_SEC As Long = 10
        t = Timer
    
        With ie
            .Visible = True
            .Navigate2 "https://www.ryanair.com/be/nl/check-in"
    
            While .Busy Or .readyState < 4: DoEvents: Wend
    
            Do
                On Error Resume Next
                Set ele = .document.getElementById("username")
                On Error GoTo 0
                If Timer - t > MAX_WAIT_SEC Then Exit Do
            Loop While ele Is Nothing
    
            If ele Is Nothing Then Exit Sub
    
            ele.Value = "resa@connections.be"
    End With
    End Sub
    
    0 讨论(0)
提交回复
热议问题