I have the following code that was supposed to look for an Explorer window and if one was available it would select it and use that window instead of using another one... thre is only one instance that I wanted the script to go to the next IE window... I was using the ie.hwnd as the reference but didn't know this number always changed... basically,
if the window has the Name of "Unit Directory - Microsoft Internet Explorer" it is to look for the next available IE window... how would I go about this either with what I have below or possibly some easier way..
if the window has the Name of "Unit Directory - Microsoft Internet Explorer" it is to look for the next available IE window... how would I go about this either with what I have below or possibly some easier way..
Code:
Sub UseExplorer()
Dim sw As Object, ie As Object
Set sw = CreateObject("Shell.Application").Windows
Dim FoundIE As Integer
Dim WS As Long
FoundIE = 0
For Each ie In sw
If FoundIE = 1 Then
ie.Navigate Site
Exit Sub
Else
If InStr(UCase(ie.FullName), "\IEXPLORE.EXE") <> 0 Then
FoundIE = FoundIE + 1
If ie.hwnd = 3540814 Then
FoundIE = 0
Else
ShowWindow ie.hwnd, 4
SetForegroundWindow ie.hwnd
ie.Navigate Site
End If
End If
End If
Next
If FoundIE = 0 Then
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.Navigate Site
End If
End Sub