'Copying Excel active sheet to the end of the workbook with Progress 4GL

I'm trying to copy an Excel active sheet to the end of the workbook with Progress 4GL. This is what I've tried so far.

DEFINE VARIABLE chExcelApplication   AS COM-HANDLE.    /* com-handle for the application */
DEFINE VARIABLE chWorkbook           AS COM-HANDLE.    /* com-handle for the workbook */
DEFINE VARIABLE iSheetCount          AS INTEGER.       /* variable to track the current sheet count */

CREATE "Excel.Application" chExcelApplication.
chWorkbook = chExcelApplication:Workbooks:Open("C:\tmp\test.xlsx").

iSheetCount = chWorkbook:sheets:COUNT.

chWorkbook:Sheets(1):COPY:after = chWorkbook:Sheets(iSheetCount). 

This is the relevant VBA code:

Sheets(1).Copy After:=Sheets(Sheets.Count)

A quick return for iSheetCount itself already giving the correct number of worksheets. How to phrase the Copy After on VBA into Progress 4GL?



Solution 1:[1]

/* On "hWorkbook:sheets:COUNT"'s right?create a new sheet */

hWorksheet = hExcelApplication:sheets:item(hWorkbook:sheets:COUNT).

hWorkbook:Worksheets:add(, hWorkSheet). /* keep the SPACE after , */

hWorksheet = hExcelApplication:sheets:item(hWorkbook:sheets:COUNT).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1