Kill Excel Process

Started by stanl, February 28, 2014, 06:30:38 AM

Previous topic - Next topic

stanl

I have an application I compiled over 2 years ago that uses a standard WB dialog, allows you to pick from two types of Excel files; Opens the selected file, 'shrinks it' to 1/8th its size, renames column headers, saves under shrink file name, imports into database table, closes Excel, returns to dialog [up to 10 files processed daily].

Has never failed and has been run on Win7 64-bit for last 6 months.  Lately, and sporadically, I might be processing say 5 files, will complete the 4th file, the dialog will return, select the 5th file, but before processing begins, an excel message pops up saying file #4 is already in use Cancel/Open-ReadOnly - but displays only a grey blank Excel dialog. Fix is to open task manager and kill the Excel *32 process.

This was a hit or miss, but now happens with more frequency. Would the recommendation be to re-compile the script adding the process extender, then include a UDF to check for EXCEL.exe and terminate() if found?


Deana

I would recommend debugging the script to try to track down the cause. It appears that Excel thinks the file is already open. Is it possible that the file might be accessed by something or someone else ? I wonder if adding a FileExist checking for the return value of 2, before trying to open the spreadsheet might help?
Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

Quote from: Deana on February 28, 2014, 07:33:59 AM
I would recommend debugging the script to try to track down the cause. It appears that Excel thinks the file is already open.

More like after the previous file was shrunk and saved and Excel closed by the script - the process is still active when trying to open the next file. And the keyword is sporadic... I run the exe with no other apps open, the Excel files are all about the same size, it will always work through 3-4 files before it hangs. The only thing I didn't mention was I recently installed the Excel Power Query add-on (to work with MySQL). This is a huge add-on and adds time to Excel loading, and perhaps unloading. I will disable it and if the problem goes away, I can look into trying to deal with it enabled. 

Deana

Hmm...You might consider adding a significant TimeDelay after the Close to give Excel time to properly close. See if that has any effect. AppExist might also be useful to confirm the process is closed.
Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

Quote from: Deana on February 28, 2014, 11:05:19 AM
Hmm...You might consider adding a significant TimeDelay after the Close to give Excel time to properly close.

I tried the timedelay, no effect. Is there any benefit with appexist versus looking for and terminating the process..

Deana

No need for an extender. Appexist checks for the process and terminateapp can be used to terminate the process.
Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

Quote from: Deana on February 28, 2014, 07:07:01 PM
No need for an extender. Appexist checks for the process and terminateapp can be used to terminate the process.

Thanks.  Just for final clarification. My :WBERRORHANDLER or a debug trace do not indicate anything wrong with the script. In fact, I can ignore the pop-up that the file is in use, and continue with the script, as it would load a new instance of Excel, shrink and save the file, import to the db table and return to the dialog - with that Excel process successfully closed. By next Tuesday, I will have 8-10 files to process and I will let you know if disabling the Power Query add-on eliminated the pop-up.

stanl

Not sure this is conclusive, but took a lot of time to test.

1. Ran script as usual, Excel process hung after 4th file processed.
2. Ran again with Power Query disabled - ran fine
3. Re-enabled Power Query - added If appexist("Excel.exe") Then TerminateApp("Excel.exe",3,0) to script in the appropriate place, re-compiled - ran fine.

Seems like the issue has to do with the Power Query add-on, and possibly specific to the laptop (company provided, PGP protected, Win7 64bit, Office 2010 32bit). Definitely not a WB problem, but a 1-line WB solution suits me fine.