我正在尝试使用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 = "[email protected]"
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 = "[email protected]"
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 = "[email protected]"
Stop
.Quit
End With
End Sub