How to tell if Excel is still active?

joek
06-23-2004, 11:02 AM
I bring up Excel w/ VBNet. If the user Exits Excel, I cannot detect this and although the user exited and excel is no longer visible, the system does not give an exception until Excel is terminated through the Task Manager.

How can I tell if Excel is no longer running and why do I need to go to the Task Manager to really kill the Excel process?

for example:

Dim xlapp As Excel.Application
Dim xlwbBook As Excel.Workbook

xlapp = CreateObject("Excel.Application")
xlwbBook = xlapp.Workbooks.Open("c:\VBExtreme.xls")

senario-1 - user exits excel
Try
if xlapp.workbooks.count < 1 then >> this does not cause an exception

senario-2 - after #1, Excel is terminated in the Task Manager
Try
if xlapp.workbooks.count < 1 then >> this does cause an exception

Thanks,
JoeK

rick_deacha
06-23-2004, 11:06 AM
How about

Set xlapp = GetObject("Excel.Application")
If xlapp Is Nothing then Msgbox "There is no Excel Application Running"

joek
06-23-2004, 11:16 AM
rick,
if xlapp is Nothing still is not true unless you goto task manager and kill excel
joe

rick_deacha
06-23-2004, 11:22 AM
This is for VB automation an Excel, I hope there are not many differences for your .NET......
http://www.xtremevbtalk.com/showthread.php?t=172296&highlight=kill+excel

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum