Search code examples
excelvbafirefoxtor

VBA To Open Links in TOR (each in a new tab)


Can you please advise how do I open a selection of links (each in a separate tab) in TOR (Firefox)?

My code works with e.g. one instance (one link from one cell in Excel) and it opens it in TOR but if I select more than one cell then it opens one and then tries to open a new instance of TOR to open another (and I cannot have two opened at once).

Sub Open_Tor()
'open hyperlink in tor
Dim tor As String
'tor = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
tor = "C:\Users\Lenovo\Desktop\Tor Browser\Browser\firefox.exe"
Dim hl As Hyperlink
On Error Resume Next
For Each hl In Selection.Hyperlinks
Shell (tor & " -url-newtab " & hl.Address)
Next hl
End Sub

If you do not have TOR you can simply change the path to your Chrome to test it (and Chrome will nicely open one link after the other, each in a separate Tab).

Thanks

PS. I cannot work with Chrome due to a daily limit of calculations I can perform on a specific server, hence the use of TOR (which changes IPs constantly).


Solution

  • Use the following two codes (paste in two separate modules). Add a button on one of the sheets (to trigger the code) if you want and direct it to the EventMacro code. Remember to adjust the alertTime and Application.Wait values to the speed/specs of your machine.

    Sub EventMacro()
    alertTime = Now + TimeValue("00:00:08")
    OpenInAnotherBrowser Sheet2.Cells(2, 2).Value 'provide a link in this location on a specific sheet (in my case Sheet2)
    Application.OnTime alertTime, "EventMacro"
    End Sub
    

    Now, thanks to this code, you will get a loop of open/close Tor browser with a specific link located in Sheet2.Cells(2, 2)! :D

    Sub OpenInAnotherBrowser(url As String)
        Dim firefoxPath As String
        Dim wshell As Object
        Dim oExec As Object
        Set wshell = CreateObject("Wscript.Shell")
       
        firefoxPath = "C:\Users\T14s\Desktop\Tor Browser\Browser\firefox.exe" 'provide path to Tor folder where firefox.exe is based
       
        If Dir(firefoxPath) = "" Then pathFireFox = "C:\Users\T14s\Desktop\Tor Browser\Browser\firefox.exe" 'provide path to Tor folder where firefox.exe is based
    
        Set oExec = wshell.Exec(firefoxPath & " " & url)
    
        Application.Wait (Now + TimeValue("0:00:05")) 'adjust based on your machine's specs
       
        oExec.Terminate
        Set wshell = Nothing
        Set oExec = Nothing
    
        Application.Wait (Now + TimeValue("0:00:03")) 'adjust based on your machine's specs
        Application.SendKeys "^+Q" 'quit Tor
    
    End Sub