how to check if excel is open

donjt81

Member
Joined
Jan 30, 2006
Messages
9
Programming Experience
Beginner
Hi I am opening MS Excel from my vb.net code. But at certain places I want to see if the Excel application is already open. If it is open then i dont need to open Excel again but if it is not open then i need to open excel.

Is there some way to check and see if excel is running in the task manager maybe, i dont know.

Can someone help?
 
If you are doing automation check if your instance of the Excel Application object is Nothing.
If you just have Excel started as a normal process and want to see if it's still there, use Process.GetProcessesByName("excel")
 
VB.NET:
Private Function CheckExcel() As Boolean
  If Ubound(Diagnostics.Process.GetProcessesByName("Excel")) > 0 Then
    Return True
  Else
    Return False
  End If
End Function


and to use this:
VB.NET:
If CheckExcel() = True Then
   'Code here for if Excel is open already
Else
   'Code here to open Excel and whatnot
End If
 
Back
Top