我正在尝试将车辆Reg的输入自动输入到.gov MOT检查器中。 第一次在输入Reg之前在代码中没有中断运行它我得到一个错误“运行时错误424对象需要”并且它引用了该行 objIE.Document.getElementById(“Vrm”)。Value = strReg
如果我运行它,agian忽略了之前的错误并且经常打开第一个窗口,那么它就会起作用。
如果我在尝试将数据输入文本框之前暂停代码,它始终有效。这显然是一个计时错误,但我不知道如何进一步检查即完全加载,我推测READYSTATE_COMPLETE会在锡上做它所说的那样吗?
任何指针都会非常感激。
TIA Andrew 完整代码
Public Function SearchBot(strReg As String)
'dimension (declare or set aside memory for) our variables
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
Dim y As Integer 'integer variable we'll use as a counter
Dim result As String 'string variable that will hold our result link
' Dim htmlDoc As HTMLDocument
'initiating a new instance of Internet Explorer and asigning it to objIE
Set objIE = New InternetExplorer
Dim strSource As String
'make IE browser visible (False would allow IE to run in the background)
objIE.Visible = True
'navigate IE to this web page (a pretty neat search engine really)
objIE.Navigate "https://vehicleenquiry.service.gov.uk/"
'objIE.navigate "https://www.check-mot.service.gov.uk/"
'wait here a few seconds while the browser is busy
Do While objIE.Busy = True Or objIE.ReadyState <> READYSTATE_COMPLETE: DoEvents: Loop
'in the search box put Registration number in the entry box
objIE.Document.getElementById("Vrm").Value = strReg
' Sheets("Sheet1").Range("A2").Value & " in " & Sheets("Sheet1").Range("C1").Value
'click the 'go' button
'wait again for the browser
objIE.Document.getElementsByName("Continue")(0).Click
Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
objIE.Document.getElementById("Correct_True").Click
objIE.Document.getElementsByName("Continue")(0).Click
GoTo SubExit
'close the browser
objIE.Quit
SubExit:
'exit our SearchBot subroutine
End Function