excel application process still runnig afer it get closed
-
I wrote excel automation using VB.Net the program takes exiting excel file name and open it, do some fixing and code for the file and let the user printpreview it. Then the program call WaitForSingleObject(hwnd,INFINITE) to pause the program until the user close the excel application. The problem: WaitForSingleObject() is waiting forever because the excel application process is still exit ( if you go to process of TaskManager you will see excel is still there) eventhough the user close excel and it is not on the screen anymore.. why the excel application didn't get closed and how can i make sure the excel application get closed when the user closed the application?
-
I wrote excel automation using VB.Net the program takes exiting excel file name and open it, do some fixing and code for the file and let the user printpreview it. Then the program call WaitForSingleObject(hwnd,INFINITE) to pause the program until the user close the excel application. The problem: WaitForSingleObject() is waiting forever because the excel application process is still exit ( if you go to process of TaskManager you will see excel is still there) eventhough the user close excel and it is not on the screen anymore.. why the excel application didn't get closed and how can i make sure the excel application get closed when the user closed the application?
It's still running because your app is holding a reference to an Excel app object.(Excel.Application) It won't close until you release that reference. But, you can't release that reference until the user clicks Close. RageInTheMachine9532
-
It's still running because your app is holding a reference to an Excel app object.(Excel.Application) It won't close until you release that reference. But, you can't release that reference until the user clicks Close. RageInTheMachine9532
-
I can't release that reference until the user clicks Close.. So how could I let WaitForSingleObject knows that excel application get closed by user? how could I resume or unpause my program when the user to close the Excel application?
You can't use WaitForSingleObject to do that because the process never closes. You have to get the event that Excel fires when the Workbook is closed. Excel will never close until you release that Excel.Application reference... RageInTheMachine9532
-
You can't use WaitForSingleObject to do that because the process never closes. You have to get the event that Excel fires when the Workbook is closed. Excel will never close until you release that Excel.Application reference... RageInTheMachine9532
When you say release the Excel.Applicatin reference means..the code should be look like following
myExcel.Applilcation.Quit() myExcle.Application = Nothing
Is it the way to realease the Excel.Application reference? If so I have it in my code and it is still not terminating Excel process. I have the function that gets the event when excel workbook is closed. How about killing the process. If I can get process ID of Excel application, is there any function that kills the process given by process ID?? -
When you say release the Excel.Applicatin reference means..the code should be look like following
myExcel.Applilcation.Quit() myExcle.Application = Nothing
Is it the way to realease the Excel.Application reference? If so I have it in my code and it is still not terminating Excel process. I have the function that gets the event when excel workbook is closed. How about killing the process. If I can get process ID of Excel application, is there any function that kills the process given by process ID??You could kill the process off, but it's not necessary. It will close completely when your app quits. Here's a little code example to do it:
Dim proc As Process appExcel.Quit() appExcel = Nothing Dim exProcess() As Process = Process.GetProcessesByName("Excel") If exProcess.Length > 0 Then For Each proc In exProcess proc.Kill() Next End If
RageInTheMachine9532
-
You could kill the process off, but it's not necessary. It will close completely when your app quits. Here's a little code example to do it:
Dim proc As Process appExcel.Quit() appExcel = Nothing Dim exProcess() As Process = Process.GetProcessesByName("Excel") If exProcess.Length > 0 Then For Each proc In exProcess proc.Kill() Next End If
RageInTheMachine9532
:eek: This will also kill off instances of Excel that were started outside of the app in question. Not only that, but using
Kill
instead ofCloseMainWindow
(in this case, not generally) will ensure two things: 1) You won't get a save prompt for any workbooks that weren't saved in the instances you didn't want closed, making it quite likely that your users will lose data if they run multiple instances of Excel while using your app. 2) Your users will not like you very much. Charlie if(!curlies){ return; } -
:eek: This will also kill off instances of Excel that were started outside of the app in question. Not only that, but using
Kill
instead ofCloseMainWindow
(in this case, not generally) will ensure two things: 1) You won't get a save prompt for any workbooks that weren't saved in the instances you didn't want closed, making it quite likely that your users will lose data if they run multiple instances of Excel while using your app. 2) Your users will not like you very much. Charlie if(!curlies){ return; }He asked, I supplied a method to do it! I know it's a bit of an overkill :eek: but its simple and it works. RageInTheMachine9532