运行时错误"424":需要对象 IE。Document.GetElementById



我正在尝试在网站上自动填写具有 excel 文件值的表单。

Sub CommandButton1_Click()
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate "https://www.ryanair.com/be/nl/check-in"
End With
Do Until IE.readyState = 4
DoEvents
Loop
   IE.document.getElementbyid("username").Value = "resa@connections.be"

End Sub

感谢您的快速回答! 我只是做了一些小的更改,因为我收到一个错误并且我使用了一个按钮。 它现在就像一个魅力!

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

对元素的存在使用定时循环

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

最新更新