Retrieving data internet explorer, Firefox & Chrome

RobMatthews

Board Regular
Joined
Nov 16, 2008
Messages
81
Hi all.

I'd like to run a macro to generate a list in excel of the urls open in all tabs of the current instances of IE (Internet Explorer), Firefox/Mozilla and Chrome. Sort of like a snap-shot of current browser states.

But I've run into a hurdle straight up: I get an "ActiveX component can't create object" when trying to get a reference to an open instance of IE, in the following fragment:

Code:
Sub RetrieveTabURLs()
Dim oIE As InternetExplorer
Set oIE = GetObject(, "InternetExplorer.Application")
'Set oIE = CreateObject("InternetExplorer.Application")
End Sub

The commented out line works fine, but the active line does not.

Equally, I can't figure out how to get a reference to Firefox.

Chrome: I haven't actually installed on this machine yet...

Are there any reference files that i should include? Or am I going about this the wrong way?

(If this is in the wrong place, please forgive me, and feel free to move it.)

TIA.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
In the past, I have tried to get your commented out line to work with FireFox, and there seems to be no way to do it. Likely the same with Chrome.

Reason being "MS owns Excel and IE". So perhaps MS does not seem to like the idea of FireFox and Excel VBA mixing. I did a lot of searching and some questions here also but seems a nogo.
 
Upvote 0
Hi Rob,

This is for listing URLs of all open IE windows:
Rich (BB code):
' ZVI:2012-02-14 http://www.mrexcel.com/forum/excel-questions/684690-retrieving-data-internet-explorer-firefox-chrome.html
Sub List_IE_Windows_URL()
  Dim a(), w
  Dim url As String
  Dim i As Long
  With CreateObject("Shell.Application")
    ReDim a(1 To .Windows.Count, 1 To 1)
    For Each w In .Windows
      If TypeName(w.Document) = "HTMLDocument" Then
        url = Replace(w.LocationURL, "%20", " ")
        i = i + 1
        a(i, 1) = url
        Debug.Print i, url
      End If
    Next
  End With
  If i Then Range("A1").Resize(i).Value = a()
End Sub
Regards
 
Last edited:
Upvote 0
That looks very good, ZVI. It has also returned "outlook:today", so I assume it returns all html-type documents, in all open programs. (At work, we only have IE,...)

Thanks very much for that; I will investigate it further tonight at home.

Cheers,
Rob.
 
Upvote 0
Interesting. I do not quite understand it though.
How does the line:
With CreateObject("Shell.Application")
know that we want only the IE application? I have firefox open with several tabs, but it is not returning this information. I had thought that it was looking at all open documents, across all applications, but obviously that isn't the case.
I've added a bit to get the page title as well, and display that, but hyperlink the URL.


Any idea how to get info from FireFox and Chrome as well?

Code:
Sub List_IE_Windows_URL()
  Dim a(), w
  Dim url As String
  Dim Title As String
  Dim i As Long
  Dim j As Long
  With CreateObject("Shell.Application")
    ReDim a(1 To .Windows.Count, 1 To 2)
    ReDim PageName(1 To .Windows.Count, 1 To 1)
    For Each w In .Windows
      If TypeName(w.Document) = "HTMLDocument" Then
        url = Replace(w.LocationURL, "%20", " ")
        Title = Replace(w.LocationName, "%20", " ")
        i = i + 1
        a(i, 1) = url
        a(i, 2) = Title
        Debug.Print i, url
      End If
    Next
  End With
  If i Then
'    Range("A1").Resize(i).Value = a()
    For j = 1 To i
        Cells(j, 1).Value = a(j, 2)
        Cells(j, 1).Hyperlinks.Add anchor:=Cells(j, 1), Address:=a(j, 1)
    Next
End If
End Sub
 
Upvote 0
As mentioned in post #3 above there seems to be no way to get "Firefox" to work with Excel VBA. Such as the following code:
Code:
Set oIE = CreateObject("Firefox.Application")
Excel and IE are both MS products. Firefox is not. Perhaps this is the reason Firefox applications cannot be interacted with through VBA in such a manner.

We would be interested if you find a workaround.
 
Upvote 0
To set URL-hyperlinks of IE windows with skipping other HTML windows like Outlook’s today try this:
Rich (BB code):
Sub Hyperlinks_of_IE_windows()
  Dim a(), w
  Dim App As String, Title As String, Url As String
  Dim i As Long, j As Long
  With CreateObject("Shell.Application")
    ReDim a(1 To .Windows.Count, 1 To 2)
    On Error Resume Next
    For Each w In .Windows
      App = w.Application
      If App = "Windows Internet Explorer" Then
        Url = Replace(w.LocationURL, "%20", " ")
        Title = Replace(w.LocationName, "%20", " ")
        i = i + 1
        a(i, 1) = Title
        a(i, 2) = Url
        'Debug.Print Title, Url
        App = vbNullString
      End If
    Next
  End With
  If i Then
    Range("A1").Resize(i).Value = a()
    For j = 1 To i
      Cells(j, 1).Hyperlinks.Add anchor:=Cells(j, 1), Address:=a(j, 2)
    Next
  End If
End Sub

Have no ideas how to get info from FireFox and Chrome because I've never used it.

Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,447
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top