How do you tell if a browser is open to a certain url?

craigachan

Registered User.
Local time
Today, 12:29
Joined
Nov 9, 2007
Messages
285
I've looked around but can't seem to narrow a search for my particular problem. I want to find out how I can write VBA to find out if a default browser is open to a particular webpage. I guess I'm going to have to find the browsers handle but I also don't know where to go from there. Any ideas or resources for me to look at?
 
Thanks Mahail for your link. But as I understand it, this will only test to see if you have a connection to the internet. I want to:

1) see if the default browser is open
2) see if a particular url is open, that is, open to a specific webpage.

Is this possible?
 
Haven't tried this but, Mihail's link will tell you if you're connected to internet
then (perhaps)
you open a new browser, navigate to specific url
check that url against your "specific webpage url

if they match you are there, if they don't match then you know that answer.

Just typing as I'm thinking.
 
Thanks Jdraw. I'm don't have much experienced in this kind of code. Could you perhaps help me with some code to do that? Thank you in advance.
 
Craig,

I found some code to find the URLs in open IE browser windows.
However, if you use a different browser (Opera, Chrome, Firefox etc),
this procedure will NOT find associated URLs. It is for IE ONLY.

Code:
'---------------------------------------------------------------------------------------
' Procedure : URLs_of_IE_windows
' Author    : mellon (based on Vladimir Zakharov material)
' Date      : 22/10/2014
' Purpose   :To identify URLs in currently open IE Browser and list the Title and URL to immediate window.
'
' *** This does NOT find Firefox, Chrome applications
' ***  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
' Note: If you want all open Windows including Windows Explorer, then
'       remove the criteria (the IF and End If) on the App  application.
'
' Original code from: Vladimir Zakharov
'---------------------------------------------------------------------------------------
'
Sub URLs_of_IE_windows()
          Dim a() As Variant
          Dim w As Variant
          Dim App As String, Title As String, Url As String
          Dim i As Long, j As Long
10        On Error GoTo URLs_of_IE_windows_Error

20        With CreateObject("Shell.Application")
30            ReDim a(1 To .Windows.Count, 1 To 2)
40            On Error Resume Next
50            For Each w In .Windows
60                App = w.Application
70                If App = "Internet Explorer" Then         ' remove this line to get all open explorer windows
80                    Url = Replace(w.LocationURL, "%20", " ")
90                    Title = Replace(w.LocationName, "%20", " ")
100                   i = i + 1
110                   a(i, 1) = Title
120                   a(i, 2) = Url
130                   Debug.Print Title, Url
140                   App = vbNullString
150               End If                                    ' remove this line to get all open explorer windows
160           Next
170       End With

180       On Error GoTo 0
190       Exit Sub

URLs_of_IE_windows_Error:

200       MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure URLs_of_IE_windows of Module IEWindows"

End Sub
 
Last edited:
Maybe, if you tell us WHY you need to know if the default browser is open at a certain page, we can find out other way to accomplish your task.
 
Thanks for your replay and this is definately something that might work.

Basically I have an access app that opens a IE browser to a prescription writing webpage. The login takes some time and I want to leave the browser open most of the day and not have to re-login every time I want to write a prescription. So In calling up the website, If my code can just check to see if it is already open, then I don't have to open another instance of the webpage. I just have to upload the patient data. Hope this makes sense.

I'll give your idea a try and let you all know.
 

Users who are viewing this thread

Back
Top Bottom