-1

Update # 2

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

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

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 - - -
  • 1
    What does your current (non-working) late binding code look like: the code you posted looks like the early binding version, so what progress have you made so far? – Tim Williams Aug 08 '16 at 18:23
  • @TimWilliams I have updated my question to show what I have now –  Aug 08 '16 at 19:55
  • 1
    Do you get the "hooked" messagebox ? `IE.Document.getElementsByClassName(TBox)` returns a collection of nodes (note the "s" in Elements), not a single element. You need something like `Set txtBox = IE.Document.getElementsByClassName(TBox)(0)` to get a reference to the first member of that collection. – Tim Williams Aug 08 '16 at 19:59
  • Yes, I did receive that msgbox prompt. Would would I do to change the textbox in the `class = masked1`? –  Aug 08 '16 at 20:01
  • 1
    edited my comment above... – Tim Williams Aug 08 '16 at 20:02
  • @TimWilliams Updated my results in the original question (because I left out the button's name). But after adding the `(0)` or a `(1)`, it still did not update the field in IE. I confirmed doing a search by the class name there are no other classes with the name. –  Aug 08 '16 at 20:25
  • 2
    Can't offer anything else without a URL – Tim Williams Aug 08 '16 at 20:49
  • I have resolved the issue by adding the site to my trusted sites and restarting IE. I believe it may have something to do with the site being in "Protected Mode". Thank you so much for the assistance! –  Aug 08 '16 at 22:01

1 Answers1

0

Get object won't work here.

What MS says about it : https://support.microsoft.com/en-gb/kb/239470

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.

Try this :

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
cyboashu
  • 10,196
  • 2
  • 27
  • 46
  • 1
    That seems to be about calling GetObject *from within IE*. I don't think that's the case here – Tim Williams Aug 08 '16 at 18:21
  • When I tested GetObject on my side, I got the error message saying, can't create ActiveX object, so I thought it makes sense. ActiveX initialization is being blocked. But you never know :) – cyboashu Aug 08 '16 at 18:24
  • @cyboashu Debugger values `2:25:25 PM [long] lTotlWin: 5` & `2:25:25 PM [obj ] IE......: Internet Explorer`. I received your msgbox prompt that it was hooked, however, it is not updating my objects `Set txtBox = IE.Document.getElementsByClassName(TBox)` w/ `txtBox.Value = Phn` –  Aug 08 '16 at 19:31