<table width="100%" border="1" bgcolor="White" style="filter
rogid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New> <font color="#0000A0">Sub</font> Example()
<font color="#0000A0">Dim</font> ie <font color="#0000A0">As</font> <font color="#0000A0">Object</font>
<font color="#008000"> 'will show true if any internet explorer window is open and</font>
<font color="#008000"> 'contains
www.mrexcel.com within the URL</font>
MsgBox FindWindowByUrl("www.mrexcel.com", , ie)
ie.navigate "http://www.mrexcel.com/board2/viewtopic.php?p=1136885#1136885"
<font color="#008000"> 'will only show true for an exact match of</font>
<font color="#008000"> 'http://www.mrexcel.com/board2/viewtopic.php?p=1136885#1136885</font>
MsgBox FindWindowByUrl("http://www.mrexcel.com/board2/viewtopic.php?p=1136885#1136885", False, ie)
<font color="#008000"> 'using your post</font>
<font color="#0000A0">If</font> FindWindowByUrl("www.google.com", , ie) <font color="#0000A0">And</font> FindWindowByUrl("www.yahoo.com") <font color="#0000A0">Then</font>
<font color="#008000"> 'run your code</font>
<font color="#0000A0">Else</font>
<font color="#008000"> 'both sessions are not open</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
<font color="#0000A0">Private</font> <font color="#0000A0">Function</font> FindWindowByUrl(URL <font color="#0000A0">As</font> String, _
<font color="#0000A0">Optional</font> PartialUrlMatch <font color="#0000A0">As</font> <font color="#0000A0">Boolean</font> = True, _
<font color="#0000A0">Optional</font> RetReference <font color="#0000A0">As</font> Object) <font color="#0000A0">As</font> <font color="#0000A0">Boolean</font>
<font color="#0000A0">Dim</font> o <font color="#0000A0">As</font> <font color="#0000A0">Object</font>
<font color="#0000A0">For</font> <font color="#0000A0">Each</font> o <font color="#0000A0">In</font> CreateObject("Shell.Application").Windows
<font color="#0000A0">If</font> PartialUrlMatch <font color="#0000A0">Then</font>
<font color="#0000A0">If</font> InStr(o.LocationURL, URL) <> 0 <font color="#0000A0">Then</font>
FindWindowByUrl = <font color="#0000A0">True</font>
<font color="#0000A0">Set</font> RetReference = o
<font color="#0000A0">Exit</font> <font color="#0000A0">Function</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">Else</font>
<font color="#0000A0">If</font> o.LocationURL = URL <font color="#0000A0">Then</font>
FindWindowByUrl = <font color="#0000A0">True</font>
<font color="#0000A0">Set</font> RetReference = o
<font color="#0000A0">Exit</font> <font color="#0000A0">Function</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">End</font> <font color="#0000A0">If</font>
<font color="#0000A0">Next</font>
<font color="#0000A0">End</font> <font color="#0000A0">Function</font>
</FONT></td></tr></table><button onclick='document.all("4202007201027750").value=document.all("4202007201027750").value.replace(/<br \/>\s\s/g,"");document.all("4202007201027750").value=document.all("4202007201027750").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("4202007201027750").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="4202007201027750" wrap="virtual">
Sub Example()
Dim ie As Object
'will show true if any internet explorer window is open and
'contains
www.mrexcel.com within the URL
MsgBox FindWindowByUrl("www.mrexcel.com", , ie)
ie.navigate "http://www.mrexcel.com/board2/viewtopic.php?p=1136885#1136885"
'will only show true for an exact match of
'http://www.mrexcel.com/board2/viewtopic.php?p=1136885#1136885
MsgBox FindWindowByUrl("http://www.mrexcel.com/board2/viewtopic.php?p=1136885#1136885", False, ie)
'using your post
If FindWindowByUrl("www.google.com", , ie) And FindWindowByUrl("www.yahoo.com") Then
'run your code
Else
'both sessions are not open
End If
End Sub
Private Function FindWindowByUrl(URL As String, _
Optional PartialUrlMatch As Boolean = True, _
Optional RetReference As Object) As Boolean
Dim o As Object
For Each o In CreateObject("Shell.Application").Windows
If PartialUrlMatch Then
If InStr(o.LocationURL, URL) <> 0 Then
FindWindowByUrl = True
Set RetReference = o
Exit Function
End If
Else
If o.LocationURL = URL Then
FindWindowByUrl = True
Set RetReference = o
Exit Function
End If
End If
Next
End Function</textarea>