【问题标题】:Converting From Early Binding to Late Binding从早期绑定转换为晚期绑定
【发布时间】:2016-08-08 17:24:05
【问题描述】:

更新 #2

我用(0) 更改了txtbox 和submitbtns 的值(也尝试了(1)),没有任何变化。

我还需要注意 Button 有一个不同的名称,我也在此处进行了相应的更新。

Dim TBox As String          'Name of object textbox to have value changed in
Dim TBtn As String          'Name of object button to be pressed
    TBox = "masked1"
    TBtn = "button"

If Not IE Is Nothing Then
    Set txtBox = IE.Document.getElementsByClassName(TBox)(0)
    Set submitBtn = IE.Document.getElementsByClassName(TBtn)(0)

    txtBox.Value = tVal
    submitBtn.Click
End If

更新 #1

因此,@cyboashu 提供的建议看起来很有希望。但是,我仍然无法让我的 txtbox 更新为 value = tVal(字符串)。

Dim oShell      As Object
Dim oWin        As Object
Dim IE          As Object
Dim lTotlWin    As Long
Dim lCtr

Debug.Print Time & " --- IE Objects & Values ---"       ' Debugger Section
Set oShell = CreateObject("Shell.Application")
    Debug.Print Time & " [obj ] oShell..: " & oShell    ' Debug oShell
Set oWin = oShell.Windows()
    Debug.Print Time & " [obj ] oWin....: " & oWin      ' Debug oWin

lTotlWin = oWin.Count - 1   '/ Starts with zero
Debug.Print Time & " [long] lTotlWin: " & lTotlWin      ' Debug lTotlWin

For lCtr = 0 To lTotlWin
    If UCase(oWin.Item(lCtr).FullName) Like "*IEXPLORE.EXE" Then
        Set IE = oWin.Item(lCtr)
    End If
Next
Debug.Print Time & " [obj ] IE......: " & IE
If Not IE Is Nothing Then
    MsgBox "Found and hooked!!"
End If

Dim TBox As String          'In the event the textbox's name changes for some reason
    TBox = "masked1"

If Not IE Is Nothing Then
    Set txtBox = IE.Document.getElementsByClassName(TBox)
    Debug.Print Time & " [obj ] txtbox..: " & txtbox
    Set submitBtn = IE.Document.getElementsByClassName(TBox)
    Debug.Print Time & " [obj ] submitBtn:" & submitBtn

    txtBox.Value = tVal
    submitBtn.Click
End If

Set shellwins = Nothing

Debug.Print Time & "- - - END SUB - - -" & E

结束子

(调试器值,如果有人关心的话)..

2:44:11 PM --- IE Objects & Values ---
2:44:11 PM [long] lTotlWin: 5
2:44:11 PM [obj ] IE......: Internet Explorer
2:44:11 PM - - - END SUB - - -

【问题讨论】:

  • 你当前(不工作的)后期绑定代码是什么样的:你发布的代码看起来像早期绑定版本,那么到目前为止你取得了什么进展?
  • @TimWilliams 我已经更新了我的问题以显示我现在拥有的内容
  • 你收到“上钩”消息框了吗? IE.Document.getElementsByClassName(TBox) 返回节点集合(注意元素中的“s”),而不是单个元素。你需要像Set txtBox = IE.Document.getElementsByClassName(TBox)(0) 这样的东西来获得对该集合的第一个成员的引用。
  • 编辑了我上面的评论...
  • 没有 URL 就无法提供其他任何东西

标签: vba internet-explorer internet-explorer-11 late-binding


【解决方案1】:

获取对象在这里不起作用。

MS 怎么说:https://support.microsoft.com/en-gb/kb/239470

调用 GetObject 以获取客户端系统上正在运行的 ActiveX 对象 将是一个很大的安全风险,因为任何运行对象 系统可以在没有直接用户许可的情况下访问,并且是 因此 Internet Explorer 不允许。没有办法改变 这种行为,无论是通过代码还是由最终用户手动进行。

试试这个:

Sub testIELateBinding()

    Dim oShell              As Object
    Dim oWin                As Object
    Dim IE                  As Object
    Dim lTotlWin            As Long
    Dim lCtr


    Set oShell = CreateObject("Shell.Application")
    Set oWin = oShell.Windows()

    lTotlWin = oWin.Count - 1 '/ Starts with zero

    For lCtr = 0 To lTotlWin
        If UCase(oWin.Item(lCtr).FullName) Like "*IEXPLORE.EXE" Then
            Set IE = oWin.Item(lCtr)
        End If
    Next


    If Not IE Is Nothing Then
        MsgBox "Found and hooked!!"
    End If


End Sub

【讨论】:

  • 这似乎是关于在 IE 中调用 GetObject 。我不认为这里是这种情况
  • 当我在我这边测试 GetObject 时,我收到错误消息说,无法创建 ActiveX 对象,所以我认为这是有道理的。 ActiveX 初始化被阻止。但你永远不知道:)
  • @cyboashu 调试器值2:25:25 PM [long] lTotlWin: 5 & 2:25:25 PM [obj ] IE......: Internet Explorer。我收到了你的 msgbox 提示它已被钩住,但是,它没有更新我的对象 Set txtBox = IE.Document.getElementsByClassName(TBox) w/ txtBox.Value = Phn
猜你喜欢
  • 1970-01-01
  • 2010-10-03
  • 2016-01-01
  • 1970-01-01
  • 2011-07-17
  • 2012-06-12
  • 2023-04-03
  • 1970-01-01
相关资源
最近更新 更多