从早期绑定转换为后期绑定 [英] Converting From Early Binding to Late Binding

查看:163
本文介绍了从早期绑定转换为后期绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更改了txtbox和submitbtns的值,其中包含(0)(和还试过(1),没有变化。

I changed the values of the txtbox and submitbtns with a (0) (and also tried (1) as well), no changes.

我还需要注意Button有一个不同的名字,我也在这里做了相应的更新。

And I also need to note that the Button has a different name and I updated accordingly here as well.

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



UPDATE#1



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

UPDATE # 1

So, things look promising with the suggestion provided by @cyboashu. However, I still cannot get my txtbox to update to the value = tVal (String).

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

End Sub

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

(Debugger values if anyone cares)..

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


推荐答案

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

Get object won't work here.

MS说的是什么: https://support.microsoft.com/en-gb/kb/239470


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

Calling GetObject to get a running ActiveX object on a client system would be a large security risk because any running object on the system could be accessed without direct user permission, and is therefore not allowed by Internet Explorer. There is no way to change this behavior, either through code or manually by an end user.

试试这个:

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

这篇关于从早期绑定转换为后期绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆