【问题标题】:Access VBA Internet Explorer automation MS Edge object disappearing访问 VBA Internet Explorer 自动化 MS Edge 对象消失
【发布时间】:2018-01-28 20:56:12
【问题描述】:

我正在使用 Access 2010 32 位在 Windows 10 机器上开发一个抓取解决方案。 问题是 IE 对象在执行期间以某种方式重置为 Nothing(在 sn-p 下面的第 17 行生成错误)。 逐步运行代码时,它似乎可以工作。 当目视检查资源管理器窗口时,它看起来像预期的那样。 我在这里做错了什么?任何想法/建议都非常感谢。

Public Function politseiKontroll(dokument As String) As String
Dim ie As Object
Dim element As Object
Dim filenum
Const URL As String = "https://www.politsei.ee/et/teenused/e-paringud/dokumendi-kehtivuse-kontroll/"
Const SIGNATURE = MODULE_NAME & "politseiKontroll"
On Error GoTo ERR_

If Len(Trim(dokument)) = 0 Or Len(Trim(dokument)) > 20 Then
   politseiKontroll = "Number on liiga pikk (20 max)"
   Exit Function
End If
1 Set ie = CreateObject("InternetExplorer.Application")
2 ie.visible = True
' 2 Prevents the URL from being added to the history list
' 4 Prevents the browser from reading the page from the disk cache
' 8 Prevents the URL from being added to the disk cache
3 ie.Navigate URL, 2 + 4 + 8    ' prevent using page from local cache
4 While ie.Busy And ie.ReadyState <> 4 ' READYSTATE_COMPLETE
5   DoEvents
6 Wend
7 If ie.Document Is Nothing Then
    ie.Quit
8    Set ie = Nothing
9    politseiKontroll = "Serveri vastus puudub"
10 End If
11 Set element = ie.Document.getElementsByName("docNumber")
12 If element.length <> 1 Then
13        ie.Quit
14     Set ie = Nothing
15     politseiKontroll = "Serveri vastuse formaat on vale"
16 End If
17 ie.Document.getElementsByName("docNumber")(0).value = dokument
While ie.Busy And ie.ReadyState <> 4 ' READYSTATE_COMPLETE
  DoEvents
Wend
18 Set element = ie.Document.getElementsByName("subButton")
19 If element.length <> 1 Then
20    ie.Quit
21    Set ie = Nothing
22    politseiKontroll = "Serveri vastuse formaat on vale"
23 End If
24 ie.Document.getElementsByName("subButton")(0).Click
25 While ie.Busy And ie.ReadyState <> 4
26   DoEvents
27 Wend
28    Stop
29    ie.Quit
30 Set ie = Nothing
31 DoEvents

EXIT_:
32    Exit Function
ERR_:
'    Dim eClone As New errClone
'    eClone.init err, , erl
    If Not ie Is Nothing Then
        ie.Quit
        Set ie = Nothing
        DoEvents
    End If
'    Set eClone = errorHandler.reportError(eClone, SIGNATURE)
'    If eClone.stopExecution Then
        Stop
'    End If
    Resume EXIT_
End Function

【问题讨论】:

    标签: vba ms-access automation internet-explorer-11


    【解决方案1】:

    如果你退出 IE,你以后不应该使用这个对象,所以:

    12 If element.length <> 1 Then
    13        ie.Quit
    14     Set ie = Nothing
    15     politseiKontroll = "Serveri vastuse formaat on vale"
    16 End If
    
    If Not ie Is Nothing Then
        ie.Document.getElementsByName("docNumber")(0).value = dokument
        While ie.Busy And ie.ReadyState <> 4 ' READYSTATE_COMPLETE
            DoEvents
        Wend
    <snip>
    

    【讨论】:

      猜你喜欢
      • 2020-07-11
      • 2018-12-18
      • 2010-10-16
      • 2023-03-08
      • 2016-11-05
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      相关资源
      最近更新 更多