I am having a problem interfaced with Excel. I'm trying to open a workbook, copy the first worksheet of the workbook and paste that worksheet into a new empty workbook. Unfortunately, I am getting two new workbooks.
Once I have the copy of the worksheet I try to update it. The problem is that the other new workbook is the one that gets updated, not the one with the copy of the original worksheet.
Can anyone see what I am doing wrong here?
Thank you for your assistance.
Anne.
Code:
DEFINE VARIABLE gchExcelApp AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE gchWorkbook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE gchSheet AS COM-HANDLE NO-UNDO.
CREATE "Excel.Application" gchExcelApp.
ASSIGN
gchExcelApp:SheetsInNewWorkbook = 1
gchWorkbook = gchExcelApp:Workbooks:Add().
DEFINE VARIABLE gchWorkbookMstr AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE gchSheetMstr AS COM-HANDLE NO-UNDO.
gchWorkbookMstr = gchExcelApp:Workbooks:Open("Template.xls").
gchSheetMstr = gchWorkbookMstr:sheets(1).
gchSheetMstr:Copy(gchSheet).
gchWorkbookMstr:Close.
gchSheet = gchWorkbook:sheets(1).
RELEASE OBJECT gchSheetMstr NO-ERROR.
RELEASE OBJECT gchWorkbookMstr NO-ERROR.
Can anyone see what I am doing wrong here?
Thank you for your assistance.
Anne.