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.
 

chuckchuckit

Well-known Member
Joined
Sep 18, 2010
Messages
541
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.
 

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,658
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:

RobMatthews

Board Regular
Joined
Nov 16, 2008
Messages
81
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.
 

RobMatthews

Board Regular
Joined
Nov 16, 2008
Messages
81
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
 

chuckchuckit

Well-known Member
Joined
Sep 18, 2010
Messages
541
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.
 

ZVI

MrExcel MVP
Joined
Apr 9, 2008
Messages
3,658
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:

Forum statistics

Threads
1,081,556
Messages
5,359,552
Members
400,533
Latest member
fpenning

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top