Determine if an application is available

 2000-04-12    VBA programming    2    226

You can use the two functions below to determine if an application is already running or if it is available on the host computer:

Function ApplicationIsRunning(ApplicationClassName As String) As Boolean
' returns True if the application is running
' example: If Not ApplicationIsRunning("Outlook.Application") Then Exit Sub
Dim AnyApp As Object
  On Error Resume Next
  Set AnyApp = GetObject(, ApplicationClassName)
  ApplicationIsRunning = Not AnyApp Is Nothing
  Set AnyApp = Nothing
  On Error GoTo 0
End Function

Function ApplicationIsAvailable(ApplicationClassName As String) As Boolean
' returns True if the application is available
' example: If Not ApplicationIsAvailable("Outlook.Application") Then Exit Sub
Dim AnyApp As Object
  On Error Resume Next
  Set AnyApp = CreateObject(ApplicationClassName)
  ApplicationIsAvailable = Not AnyApp Is Nothing
  Set AnyApp = Nothing
  On Error GoTo 0
End Function