1
votes

I am looking to automate our reporting. We currently have 5 Tabs in Firefox that we refer to for reporting. Each Tab has a unique url that changes each morning. We then have to each morning update these URLs (from an excel speadsheet). I would like to automate this. I do have a few constraints on this though. I cannot open a new tab for each new url (so basically it needs to be a url replace in each tab). I have looked into selenium but cannot get it to work

http://www.makeuseof.com/tag/using-vba-to-automate-internet-explorer-sessions-from-an-excel-spreadsheet/

and

http://www.makeuseof.com/tag/how-to-automate-firefox-or-chrome-with-vba-and-selenium/

So I was wondering if it could be done another way either using pure VBA or a batch file?

1
Not that I know the answer as I hardly work with FF from VBA but I am curios to know why FF and not IE which actually lets you automate it effortlessly from VBA? - Siddharth Rout
@SiddharthRout - I would do it in IE but I cannot find add-ons that autorefreshes the page and Tiles them like addons.mozilla.org/en-US/firefox/addon/tab-auto-reload/… for the auto-reload and addons.mozilla.org/en-US/firefox/addon/tile-tabs/?src=search for the tiling - Johan Rheeder
[IE Autorefresh] See THIS or THIS - Siddharth Rout
[IE Tiling] Not sure if there is an AdOn but you can open the sites in different windows rather than tabs and then right click and choose "Show windows stacked" or "Show windows side by side" - Siddharth Rout
@SiddharthRout - The problem with show side by side is it can look very unclean but if the coding to "Update" the URLs are easy and can be automated then I am willing to consider it - Johan Rheeder

1 Answers

1
votes

You need to add a reference to Microsoft Internet Controls and Microsoft Shell Controls and Automation. See screenshot below.

enter image description here

Code:

Sub Work_With_Open_IE_Instance()
    Dim objShell As Shell
    Dim objIE As InternetExplorer
    Dim objWin As Object

    Set objShell = New Shell

    For Each objWin In objShell.Windows
        If TypeName(objWin.Document) = "HTMLDocument" Then
            Set objIE = objWin

            '~~> This will display the URL of the IE which we will use to bind
            Debug.Print objIE.LocationURL

            '~~> Example to bind
            '~~> Change URL to your existing URL
            Select Case objIE.LocationURL
                Case "https://www.google.com"
                    With objIE
                        .Refresh
                        '
                        '~~> Rest of the code
                        '
                    End With
                Case "http://in.msn.com"
                    With objIE
                        .Refresh
                        '
                        '~~> Rest of the code
                        '
                    End With
                End Select
            End If
        End If
    Next objWin
End Sub

The Select Case is just for demonstration purpose. If you want to work with them one after the other then don't use Select Case. Use If/EndIf one after the other.