Excel com object add worksheet

Hi

heres my code but it does not work brings error

Invalid component -handle referenced while processing method/statements Worksheets


chWorkbook = chWorkbook = chExcelApplication:Workbooks:Add().
chWorkSheet = chExcelApplication:Sheets:Item(1).
chWorkSheet2 = chExcelApplication:Sheets:Item(2).
chWorkSheet3 = chExcelApplication:Sheets:Item(3).

chExcelApplication:Sheets:Item(2):name = "1 day Late".
chExcelApplication:Sheets:Item(3):name = "2 days Late".

chWorksheet4 = chWorkbook:Worksheets:ADD().
 
DEFINE VARIABLE chWorkbook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorkSheet AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorkSheet2 AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorkSheet3 AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO.
CREATE "Excel.Application" chExcelApplication.

ChExcelApplication:VISIBLE = TRUE.
chWorkbook = chExcelApplication:Workbooks:ADD.
chWorkSheet = chExcelApplication:Sheets:Item(1).
chWorkSheet2 = chWorkbook:Worksheets:ADD().
chWorkSheet2 = chExcelApplication:Sheets:Item(2).
chWorkSheet3 = chWorkbook:Worksheets:ADD().
chWorkSheet3 = chExcelApplication:Sheets:Item(3).
chExcelApplication:Sheets:Item(2):name = "1 day Late".
chExcelApplication:Sheets:Item(3):name = "2 days Late".

and so on...
 
Cheers works now

ok now if i have spreadsheet with 3 sheets on it already how can i append to start from the 4th sheet.

when i do it now it puts sheet4 right at the front before sheet1

cheers]
 
DEFINE VARIABLE chWorkSheet3 AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chWorkSheet4 AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO.
CREATE "Excel.Application" chExcelApplication.
ChExcelApplication:VISIBLE = TRUE.
chWorkbook = chExcelApplication:Workbooks:ADD.
chWorkSheet = chExcelApplication:Sheets:Item(1).
chWorkSheet2 = chWorkbook:Worksheets:ADD().
chWorkSheet2 = chExcelApplication:Sheets:Item(2).
chWorkSheet3 = chWorkbook:Worksheets:ADD().
chWorkSheet3 = chExcelApplication:Sheets:Item(3).
chExcelApplication:Sheets:Item(2):name = "1 day Late".
chExcelApplication:Sheets:Item(3):name = "2 days Late".
chWorkSheet4 = chWorkbook:Worksheets:ADD().
chWorkSheet4:MOVE(,chWorkSheet3).
chWorkSheet4 = chExcelApplication:Sheets:Item(4).

just make sure this line right after the add line

move(,...(some worksheet)) --> place after some worksheet
move(...(some worksheet),) --> place before some worksheet
 
Back
Top