Excel Illegal Operation

Chris Kelleher

Administrator
Staff member
After running the code below, when I close the Excel application I receive
the error message "Excel has performed an illegal operation". It doesn't
seem to like how I switch to the second sheet (if I comment that out I don't
receive the message). Could someone point me in the right direction for the
appropriate way to switch to the second sheet?

<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>
DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorkbook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorksheet AS COM-HANDLE NO-UNDO.

CREATE "Excel.Application" chExcelApplication.
chExcelApplication:Visible = TRUE.
chWorkbook = chExcelApplication:Workbooks:Add().
chWorkSheet = chExcelApplication:Sheets:Item(1).
/* code to fill in data and formatting */
chWorkSheet = chExcelApplication:Sheets:Item(2). /* <-- Something wrong with
this? */
/* code to fill in data and formatting */
RELEASE OBJECT chWorksheet.
RELEASE OBJECT chWorkbook.
RELEASE OBJECT chExcelApplication.
[/code]

Progress 8.2C - Win98

Thanks,
David Hopper
Lowen Corporation
 

Chris Kelleher

Administrator
Staff member
Hi David,

you have forgotten about releasing handle of sheet 1.
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>

CREATE "Excel.Application" chExcelApplication.
chExcelApplication:Visible = TRUE.
chWorkbook = chExcelApplication:Workbooks:Add().
chWorkSheet = chExcelApplication:Sheets:Item(1).

RELEASE OBJECT chWorksheet. /* !!!!!!!!!!!!!!!!!!!! */

chWorkSheet = chExcelApplication:Sheets:Item(2).

RELEASE OBJECT chWorksheet.
RELEASE OBJECT chWorkbook.
RELEASE OBJECT chExcelApplication.
[/code]

best regards

Tom
 
Top