purpose
Have an Excel file with a Search button that opens a user program. This program is used for research. If the program is already open when the user clicks on the button, make it pop up and focus on that given program.
Current situation
Here is the code I'm trying to use to make it work:
Search button
Private Sub btnSearch_Click()
Dim x As Variant
Dim Path As String
If Not IsAppRunning("Word.Application") Then
Path = "C:\Tmp\MyProgram.exe"
x = Shell(Path, vbNormalFocus)
End If
End Sub
IsAppRunning ()
Function IsAppRunning(ByVal sAppName) As Boolean
Dim oApp As Object
On Error Resume Next
Set oApp = GetObject(, sAppName)
If Not oApp Is Nothing Then
Set oApp = Nothing
IsAppRunning = True
End If
End Function
This code will only work when I put "Word.Application" as an executable. If I try to put "MyProgram.Application", the function will never see that the program is running. How can I find that "MyProgram.exe" is currently open?
In addition, I will need to focus on it ...