本文介绍了运行时错误'424':对象必需IE.Document.GetElementById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Excel文件的值自动完成网站上的表单.

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 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 = "[email protected]"


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 = "[email protected]"

        Stop
        .Quit
    End With
End Sub

这篇关于运行时错误'424':对象必需IE.Document.GetElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 22:36