最近在做的一个功能,就是用excel表格通过IE对象实现在线转换GPS坐标的功能,代码如下
Private Sub test()
    Dim str, t, t1, s1, s, l As String
    Dim d, g, q, i As Long
    Dim nowtime, clicktime, retime As Single
    Dim ie As Object
    i = 0
        Set ie = CreateObject("InternetExplorer.application")
        ie.Navigate "https://tool.lu/coordinate/"  '访问网站
        ie.Visible = True '打开后显示网页
        nowtime = Timer
        Do Until ie.ReadyState = 4 And ie.busy = False '如果IE加载完成
            DoEvents '在窗体加载时转交操作权
            If Abs(Timer - nowtime) >= 10 Then
                ie.qiut
                MsgBox "超时"
                Sheet1.Application.StatusBar = ""
                Exit Sub
            End If
        Loop
                With ie
                    .document.getelementbyid("wgs84").innertext = ""
                    .document.getelementbyid("src_coordinate").Value = Trim(Sheet1.Range("C1" ))
                    .document.all.tags("input")(2).Checked = "1"
                    .document.all.tags("button")(1).Click
                    clicktime = Timer '控制循环间隔
                    Do Until .ReadyState = 4 And .busy = False And Timer > clicktime + 0.3 '如果IE加载完成
                        DoEvents '在窗体加载时转交操作权
                        If Abs(Timer - clicktime) >= 10 Then
                            ie.Quit
                            Set ie = Nothing
                            MsgBox "超时"
                            Sheet1.Application.StatusBar = ""
                            Exit Sub
                        End If
                    Loop
                End With
            End If
End Sub
这个代码调试状态逐条运行没一点问题,可就是直接连续运行的话,那个网站一打开,我能看到坐标系的那个单选框从最初的第三个蹦到第二个,说明.document.all.tags("input")(2).Checked = "1"成功执行了,但是不到0.1秒的时间就迅速自动跳到了第三个然后click了。这样我查出来的坐标就不对了这问题该怎么解决?
而且奇怪的是如果我用循环批量查询多个数据时往往也是最开始的一两个数据会有问题,到后面又都没问题了目前我的解决办法简单粗暴,就是在第一个DO循环条件里加上timer>clicktime+2,就没问题了,但是感觉这种方法太被动而且不方便
各位大神有更好的解决方法吗?