【发布时间】: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