I had another post regarding a different issue on the same overall problem here: Converting From Early Binding to Late Binding. I now have a new issue with my coding (which I will post a portion of it below), where if I have Internet Explorer open with multiple tabs, my code no longer fills in the text boxes - even if the tab is the one currently being viewed. As soon as I close all other tabs, the code runs flawlessly.
If the tab was named Tab1
at the URL: https://sub.website.com/dir/
, how can I have the forms filled out on this site with multiple tabs?
Here is the code being used (courtesy of cyboashu and help from Tim Williams):
Sub Test()
' Code Cut Here
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
Dim TBtn As String
TBox = "masked1"
Tbtn = "button"
If Not IE Is Nothing Then
Set txtBox = IE.Document.getElementsByClassName(TBox)(0)
Debug.Print Time & " [obj ] txtbox..: " & txtbox
Set submitBtn = IE.Document.getElementsByClassName(Tbtn)(4)
Debug.Print Time & " [obj ] submitBtn:" & submitBtn
txtBox.Value = tVal
submitBtn.Click
End If
End Sub
Use the Shell Windows to loop through and keep the first one that you found. Closing remaining IE tabs/windows.
To use tab names for identification this will work :
Here's what i typically use when automating an existing IE window: