申请时间错误; VBA 到 IE

Application on time error ; VBA to IE

所以基本上如果我 运行 这段代码只运行一次就很好,有时它会再次运行第二次或第三次,等等......但迟早它总会给出一个错误;在此行结束 'Set ieElement = ieApp.Document.getElementByID("ss-submit")' "Run-time error '424': Object required"。有什么办法可以防止这种情况发生吗?

Private Sub Workbook_Open()  
    Call WriteToGoogleForm  
End Sub 

Sub WriteToGoogleForm()  
    Application.OnTime Now + TimeValue("00:10"), "WriteToGoogleForm" 
    Dim winGas As Double  
    Application.CalculateFull  
    winGas = Worksheets("Sheet1").Cells(1, 3).Value  
    Call UseInternetExplorer(winGas)     
End Sub

Sub UseInternetExplorer(wg As Double)
    Dim ieApp As New SHDocVw.InternetExplorer

    ieApp.Visible = True
    ieApp.Navigate "www.form.com"

    Do While ieApp.Busy And Not ieApp.ReadyState = READYSTATE_COMPLETE  
        DoEvents
    Loop

    Dim ieElement As Object  

    Set ieElement = ieApp.Document.getElementByID("ss-submit")  
    Do While ieApp.Busy  
        DoEvents
    Loop  

    Set ieElement1 = ieApp.Document.getElementByID("entry_106413780")  
    Do While ieApp.Busy  
        DoEvents  
    Loop 

    ieElement1.Value = wg
    Do While ieApp.Busy
        DoEvents
    Loop

    ieElement.Click  
    Do While ieApp.Busy  
        DoEvents  
    Loop  

    ieApp.Quit  

End Sub

似乎由于某种原因缺少 ss-submit 元素。尝试添加空验证:

Set HTMLdoc = ieApp.Document

If Not IsNull(HTMLdoc.getElementByID("ss-submit"))