How do I find out if another program is running from within my program. IE. Is excel currently active and if not then I'll start it.
I know how to start Excel etc... but how do I detect if it is already running.
Thanks in advance,
Steve.
Printable View
How do I find out if another program is running from within my program. IE. Is excel currently active and if not then I'll start it.
I know how to start Excel etc... but how do I detect if it is already running.
Thanks in advance,
Steve.
I just can't remeber what classname you have to pass but you could find out. Anyway if you know the classname you can use findwindow that will return the handle if there is at least one instance of excel running. otherways it will return 0
Code:'in declarations
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'in code
wnd = FindWindow(classname,vbnullstring)
Try this:
Code:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Sub Command1_Click()
Retval = FindWindow("XLMAIN", 0&)
If Retval = 0 Then
MsgBox ("Excel is not running")
Else
MsgBox ("Excel is running")
End If
End Sub