Consultor Eletrônico



Kbase 21828: ActiveX: Lingering Process with Excel and COM-HANDLES
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   25/02/2002
SUMMARY:

After attempting to open a non-existent file in Excel (using the NO-ERROR option), and then closing Excel, you could see a still-active process, suggesting that it hasn't terminated correctly.

EXPLANATION:

For example, you might do a print preview of an existing Excel file.

DEFINE VARIABLE w-hexcel AS COM-HANDLE.
DEFINE VARIABLE w-hsheet AS COM-HANDLE.
DEFINE VAR w-invname AS CHAR INITIAL "c:\temp\Book1.xls".

CREATE "Excel.Application" w-hexcel.

assign w-hsheet = w-hexcel:Workbooks:open (w-invname,,TRUE,,,,,,,,,,false)
NO-ERROR.
ASSIGN w-hexcel:visible = true.

w-hexcel:worksheets:PrintPreview(FALSE).
w-hexcel:ActiveWindow:Zoom = 150.
w-hexcel:screenupdating = FALSE.
w-hexcel:screenupdating = TRUE.
w-hsheet:activate().


IF w-hexcel:ActiveWindow:Close() THEN DO:
NO-RETURN-VALUE w-hexcel:Workbooks:close().
RELEASE OBJECT w-hsheet.
RELEASE OBJECT w-hexcel.
OS-DELETE value(w-invname).
END.

The first run of this procedure will work correctly. However, deleting the file and then re-running the procedure will result in a
handle/process still being displayed in the Task Manager.

SOLUTION:

The solution is to create a WORKSHEET without any value, as in the following example:


DEFINE VARIABLE w-hexcel AS COM-HANDLE.
DEFINE VARIABLE w-hsheet AS COM-HANDLE.
DEFINE VAR w-invname AS CHAR INITIAL "c:\temp\Book1.xls".

CREATE "Excel.Application" w-hexcel.

assign w-hsheet = w-hexcel:Workbooks:open (w-invname,,TRUE,,,,,,,,,,false)
NO-ERROR.
ASSIGN w-hexcel:visible = true.

IF VALID-HANDLE(w-hsheet) THEN
DO:
w-hexcel:worksheets:PrintPreview(FALSE).
w-hexcel:ActiveWindow:Zoom = 150.
w-hexcel:screenupdating = FALSE.
w-hexcel:screenupdating = TRUE.
w-hsheet:activate().
END.

ELSE ASSIGN w-hsheet = w-hexcel:Workbooks:ADD.


IF w-hexcel:ActiveWindow:Close() THEN DO:
NO-RETURN-VALUE w-hexcel:Workbooks:close().
RELEASE OBJECT w-hsheet.
RELEASE OBJECT w-hexcel.
OS-DELETE value(w-invname).
END.