Private Sub CommandButton1_Click()
Dim IE As Object
Dim i As Integer
i = 2
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.mywebsite.com/Entry_Form.aspx"
IE.Visible = True
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
Do Until Cells(i, 1) = nil
IE.Document.All("ctl00$MainContent$txtacccrop").Value = ThisWorkbook.Sheets("Sheet1").Cells(i, 1)
IE.Document.All("ctl00$MainContent$btnsearch").Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
IE.Document.All("ctl00$MainContent$txtfather").Value = ThisWorkbook.Sheets("Sheet1").Cells(i, 2)
IE.Document.All("ctl00$MainContent$btnconfirm").Click
i = i + 1
While IE.Busy
DoEvents 'wait until IE is done loading page.
Wend
Loop
End Sub
当第一次点击事件发生时,页面会加载新字段 ctl00 $ MainContent $ txtfather 。行显示错误
IE.Document.All("ctl00$MainContent$txtfather").Value = ThisWorkbook.Sheets("Sheet1").Cells