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
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