Open multiple browser windows with different URLs

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,233
Office Version
  1. 365
Platform
  1. Windows
Hey All

What I'm trying to do is use Excel to open 4 different instances of the default browser, each with a different URL

So, in Cell A1 I've got something I want to search for.

I want to be able to click a button and open 4 different browser windows, one going to Google, one going to Bing etc etc

Normally I just use FollowHyperlink when I just want to open a website but it just adds new tabs instead of new windows, even if I specify NewWindow

VBA Code:
Sub TestSearch()
    ActiveWorkbook.FollowHyperlink Address:="https://google.co.uk", NewWindow:=True
    ActiveWorkbook.FollowHyperlink Address:="https://bing.co.uk", NewWindow:=True
End Sub

I've Googled and found other code that does it through shell commands but that does the same thing, just adds more tabs.

Can anyone help at all?

Thank you.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Your code works for me, but you can try this approach ( I did not test this one).
 
Upvote 0
Thanks for taking a look Micron.

The example you linked to does actually work, but also opens up Internet Explorer to do it (!) - I need it to be the default browser because the end product will have multiple users, some won't have Firefox or Chrome installed so I can't even specify to use a certain browser

I have been able to get where I want to by changing the Preferences in the browser, I use Firefox - If I go to the preferences there I get the option in a tickbox there to open a link in a new window.

The code works then, but then of course everything opens in a new Window which isn't what I want.
 
Upvote 0
I thought I got 2 separate windows, each with one tab but I was mistaken. Sorry about that.
This seems to work but will need tweaking to get the default browser info. More on that at the end.
VBA Code:
Public Sub OpenUrl()
Dim strUrl As String, strBrowserPath As String, strNewWindow As String

strUrl = "www.bbc.co.uk"
strBrowserPath = "C:\Program Files\Mozilla Firefox\Firefox.exe "
strNewWindow = "/new-window "
Shell strBrowserPath & strUrl

strUrl = "https://google.ca"
Shell strBrowserPath & strNewWindow & strUrl

strUrl = "https://bing.co.uk"
Shell strBrowserPath & strNewWindow & strUrl

End Sub
Assuming there is a way to get the default browser path, then I guess you'd need to get that and assign the string to the path variable. If that is not possible, then perhaps present a message (likely a small userform) with the choices you've coded for in a select case block. Selection would be option buttons I guess, or combobox.

Giving credit where due, I found this at

Somewhere (either in that thread or the one linked to at AccessForums.net) is a comment about the new window switch having different syntaxes for different browsers.
 
Upvote 0
Apparently getting the default browser is doable. I got lots of hits on opening with the default, but not too many for getting the default program data. This guy has been around a long time, so I'd try his method.
 
Upvote 0
Thanks for taking a look Micron.

The example you linked to does actually work, but also opens up Internet Explorer to do it (!) - I need it to be the default browser because the end product will have multiple users, some won't have Firefox or Chrome installed so I can't even specify to use a certain browser

I have been able to get where I want to by changing the Preferences in the browser, I use Firefox - If I go to the preferences there I get the option in a tickbox there to open a link in a new window.

The code works then, but then of course everything opens in a new Window which isn't what I want.

Essentially you're trying to get a certain behavior to take place on a particular PC regardless of the user settings. This type of thing is not very well suited for VBA. I can see how this can be done using VB scripting but that is NOT the same thing as VBA. You can incorporate VB script snippets into a VBA routine but they are NOT the same things.

Here's something you can consider as a work around solution:

Put all your URLs into a worksheet, then save it as a single file webpage. *.mhtml file. You can also put those links into a Microsoft Word document - your choice.

Then email that MHTML file to your co-workers whatever. Then they can open it on their end using the browser of their choice. If you're trying to get each URL to open up in a separate tab - that's a PER USER setting. Just give them specific instructions to on how to do that.
 
Last edited:
Upvote 0
I forgot to mention 1 other item. If you know how to edit HTML (or MHTML) files, you can modify the coding so that each link opens up in a separate tab. Typically it is done like this:

Code:
<a href="https://www.somewebsite1.com" target="_blank">https://www.somewebsite1.com</a><br>
<a href="https://www.somewebsite2.com" target="_blank">https://www.somewebsite2.com</a><br>
etc.

Modifying in this manner would force each URL to open in a separate tab regardless of the user's setting on the PC because it's embedded into the MHTML file itself.
 
Upvote 0
Thanks for all the help, suggestions and links folks but I don't think this can actually be done the way it's been requested of me.

They wanted to be able to have the four new windows open at the same time so they could easily compare one result to another, it was just a quailtity of life thing more than anything else, nothing they can't sort themselves with a few clicks.

When they asked me about it I thought it'd be easier based upon me knowing you could open the browser with the new window flag.

As always, I appreciate everyones time but I think I'm going to teach them about opening a tab in a new window instead of spending more time on this :)
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,087
Members
452,611
Latest member
bls2024

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