Order excel sheets at runtime

Elite237

New Member
Hi, I have a doubt about how I can order the sheets in excel at the moment of generate it.

I create the sheets with the next sentences:

chWorkSheet = chExcelApplication:Sheets:ADD().
chWorkSheet = chExcelApplication:Sheets:ITEM(1).

but the excel sheets begin to be created from right to left, and I want to do it from left to right.

Thanks
 
Check out the Excel reference at MSDN which is very useful for this kind of work.

It shows that the Add method by default Adds a worksheet before the current worksheet, but you can provide the worksheet to add the sheet after by passing the second parameter.

Example:

Code:
DEFINE VARIABLE chExcel       AS COM-HANDLE.
DEFINE VARIABLE chWorkbook    AS COM-HANDLE.
DEFINE VARIABLE chWorksheets  AS COM-HANDLE EXTENT 2.

CREATE "Excel.Application":U chExcel.
chWorkbook = chExcel:Workbooks:Add(-4167).
chWorksheets[1] = chworkbook:Worksheets(1).
chWorksheets[2] = chWorkbook:Worksheets:Add( , chWorksheets[1] ). /* <-- second parameter! */
chExcel:Visible = TRUE.
chExcel:DisplayAlerts = FALSE.

MESSAGE "Quitting":U VIEW-AS ALERT-BOX.

chExcel:Quit().
 
Back
Top