Opening a list of URLs in a browser?

Why

New Member
Joined
Oct 11, 2009
Messages
1
I have a list of URLs in Excel. I am trying to open them in Firefox, one per tab.

I found that the code below SOMETIMES works, if I set a time delay in myTimer. However, it sometimes opens another "session" of Firefox for each URL.

Is there is a better way to do this? For example, I wondered if it is possible to replace myTimer with an instruction that waits until ShellExecute is finished after each call? Is there such an instruction?

Thanks in advance.

MY MACRO (STRIPPED)
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Sub OpenMyBrowser()
Dim myI, myCountI As Integer
Rem myCountI IS THE NUMBER OF URLS TO OPEN
myCountI = 10
myI = 0

Do While myI < myCountI
URLtoOpen = ActiveCell.Offset(myI, 0).Value
If URLtoOpen = "" Then
MsgBox "Encountered a blank URL"
GoTo myEnd
End If
ActiveCell.Offset(myI, 0).Interior.Color = vbYellow
ShellExecute 0, "Open", "Firefox.exe", URLtoOpen, vbNullString, sw_showmaximised
myI = myI + 1
myTimer
loop
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Is FF VBA compatible? Can you do something like:
Code:
Dim invApp As FireFox.Application
Set invApp = GetObject(, "FireFox.Application")
and then use any methods etc of the app? You would have to include the Mozilla library in your references I would imagine (if they exist, of course).
An alternative (or indeed, error check), might be to find which browser is the default first...

Let me know how you go, 'cos that'd be interesting.
 
Upvote 0
I suspect -- but am not sure -- that that is a function of how FF is configured. If it is configured to open new windows in new tabs, your shellexecute URLs will go in new tabs.

Also, you can try RobMatthews' suggestion but as far as I know FF is not "COM aware." So, the CreateObject function will fail.

Finally, and obviously I don't know what you are trying to accomplish, you may want to look at the FollowHyperlink method of either the workbook or the worksheet.

I have a list of URLs in Excel. I am trying to open them in Firefox, one per tab.

I found that the code below SOMETIMES works, if I set a time delay in myTimer. However, it sometimes opens another "session" of Firefox for each URL.

Is there is a better way to do this? For example, I wondered if it is possible to replace myTimer with an instruction that waits until ShellExecute is finished after each call? Is there such an instruction?

Thanks in advance.

MY MACRO (STRIPPED)
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Sub OpenMyBrowser()
Dim myI, myCountI As Integer
Rem myCountI IS THE NUMBER OF URLS TO OPEN
myCountI = 10
myI = 0

Do While myI < myCountI
URLtoOpen = ActiveCell.Offset(myI, 0).Value
If URLtoOpen = "" Then
MsgBox "Encountered a blank URL"
GoTo myEnd
End If
ActiveCell.Offset(myI, 0).Interior.Color = vbYellow
ShellExecute 0, "Open", "Firefox.exe", URLtoOpen, vbNullString, sw_showmaximised
myI = myI + 1
myTimer
loop
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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