The method I use first checks whether the application is running.
If it is, then GetObject is used. If not running, then CreateObject is used.
Here are two methods of using the idea taken from one of my apps
They are for Excel & Outlook but will work for any application that you know how to reference
Method 1 - requires error handling
Code:
Function MyFunctionName()
On Error Goto Err_Handler
...other unrelated code here if needed
'Start Excel
On Error Resume Next
Dim oExcel As Object
Set oExcel = GetObject(, "Excel.Application") 'Bind to existing instance of Excel
If Err.Number <> 0 Then 'Could not get instance of Excel, so create a new one
Err.Clear
On Error GoTo Error_Handler
Set oExcel = CreateObject("Excel.Application")
bExcelOpened = False
Else 'Excel was already running
bExcelOpened = True
End If
On Error GoTo Error_Handler
...more unrelated code here
Set oExcel = Nothing
Exit_Handler:Exit Function
Err_Handler:MsgBox "Error " & Err.Number & " in MyFunctionName routine: " & Err.Description
Resume Exit_Handler
Exit Function
Method 2 - uses external function
Code:
Function MyFunctionName()
On Error Goto Err_Handler
...other unrelated code here if needed
Dim objOutlook As Object
' Create the Outlook session.
If IsAppRunning("Outlook.Application") = True Then
'Use existing instance of Outlook
Set objOutlook = CreateObject("Outlook.Application")
Else
'Could not get instance of Outlook, so create a new one
Path = GetAppExePath("outlook.exe") 'determine outlook's installation path
Shell (Path), vbMinimizedFocus 'start outlook
Do While Not IsAppRunning("Outlook.Application")
DoEvents
Loop
Set objOutlook = GetObject(, "Outlook.Application") 'Bind to new instance of Outlook
End If
...more unrelated code here if needed
Set objOutlook = Nothing
Exit_Handler:Exit Function
Err_Handler:MsgBox "Error " & Err.Number & " in MyFunctionName routine: " & Err.Description
Resume Exit_Handler
Exit Function
For method 2, place this function in a standard module
Code:
Function IsAppRunning(sApp As String) As Boolean On Error GoTo Error_Handler
Dim oApp As Object
Set oApp = GetObject(, sApp)
IsAppRunning = True
Error_Handler_Exit:
On Error Resume Next
Set oApp = Nothing
Exit Function
Error_Handler:
Resume Error_Handler_Exit
End Function
Hopefully you can see how to incorporate one of these methods into your interestingly named GetIEatURL function
If not, get back to me
Hope that helps