Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Internet explorer 时间误差的应用;VBA到IE_Internet Explorer_Excel_Vba - Fatal编程技术网

Internet explorer 时间误差的应用;VBA到IE

Internet explorer 时间误差的应用;VBA到IE,internet-explorer,excel,vba,Internet Explorer,Excel,Vba,所以基本上如果我只运行这段代码一次,它就工作得很好,有时它第二次或第三次再次工作,等等。。。但迟早它总会出错;结束于此行“Set ieElement=ieApp.Document.getElementByID(“ss submit”)”“运行时错误“424”:需要对象”。有没有办法防止这种情况发生 Private Sub Workbook_Open() Call WriteToGoogleForm End Sub Sub WriteToGoogleForm() A

所以基本上如果我只运行这段代码一次,它就工作得很好,有时它第二次或第三次再次工作,等等。。。但迟早它总会出错;结束于此行“Set ieElement=ieApp.Document.getElementByID(“ss submit”)”“运行时错误“424”:需要对象”。有没有办法防止这种情况发生

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"))  

thx,这避免了错误,保持一切良好和工作;但我仍然不明白为什么有时它会发现这个“ss提交”,有时它不会…很高兴它帮助了你原来的问题…别忘了投票!:)我假设您的HTML元素是由服务器端代码生成的,并且id会动态更改?我不这么认为,不;不知道你是否能看到这个,我想你应该能看到这个;无论如何,id来自此网页的源代码,它们不会更改/是随机生成的;或者至少我认为他们没有尝试“HTMLdoc.All(“submit”)而不是“HTMLdoc.getElementByID(“ss submit”)”;但同样的问题也发生了。。。