Home » Developer & Programmer » Forms » Using copy Excel sheet via OLE2... (Forms 6.0)
Using copy Excel sheet via OLE2... [message #521443] Tue, 30 August 2011 00:41
VTally
Messages: 1
Registered: August 2011
Location: Russia
Junior Member
Please help with some problem (or a feature) with method Copy for Excel worksheet via OLE2.
Here is my code:

oExcel OLE2.OBJ_TYPE;
Book1 OLE2.OBJ_TYPE;
Book2 OLE2.OBJ_TYPE;
Sheet1 OLE2.OBJ_TYPE;
Sheet2 OLE2.OBJ_TYPE;
oArgList OLE2.LIST_TYPE;
--
oExcel := OLE2.Create_Obj ('Excel.Application');

oWorkbooks := OLE2.GET_OBJ_PROPERTY (pExcelApp, 'Workbooks');
--
oArgList := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (oArgList, 'C:\TEST1.XLS');
Book1 := OLE2.Invoke_Obj (OLE2.GET_OBJ_PROPERTY (oExcel, 'Workbooks'), 'Open', oArgList);
OLE2.DESTROY_ARGLIST (oArgList);

oArgList := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (oArgList, 'C:\TEST2.XLS');
Book2 := OLE2.Invoke_Obj (OLE2.GET_OBJ_PROPERTY (oExcel, 'Workbooks'), 'Open', oArgList);
OLE2.DESTROY_ARGLIST (oArgList);

oArgList := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (oArgList, 1);
Sheet1 := OLE2.Get_Obj_Property (Book1, 'WorkSheets', oArgList);
OLE2.DESTROY_ARGLIST (oArgList);

oArgList := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG (oArgList, 2);
Sheet2 := OLE2.Get_Obj_Property (Book2, 'WorkSheets', oArgList);
OLE2.DESTROY_ARGLIST (oArgList);

This code works normally without any surprises.
And now I try to invoke method Copy for Sheet1 with this code.

oArgList := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG_OBJ (oArgList, Sheet2);
OLE2.INVOKE (Sheet1, 'Copy', oArgList);
OLE2.DESTROY_ARGLIST (oArgList);

As a result I have no OLE error (I use exception block to catch OLE2.OLE_ERROR), and no copying Sheet1 from Book1 to Book2 before Sheet2 as I've expected (as described in Excel help system). But if I exclude using oArgList and invoke method Copy with this code:

OLE2.INVOKE (Sheet1, 'Copy');

everything is OK - Excel creates new workbook and copy Sheet1 to it following Excel help system in details. And here's my problem and asking for help: What's wrong in my code where I use OLE2.ADD_ARG_OBJ? Is it a bug or a feature in OLE2.ADD_ARG_OBJ method? Or I've done a mistake and try to use this method in wrong way? (One little addition: names of sheets in Book1 and Book2 are different).

Here's my environment: Windows XP Prof SP3, Oracle*Forms 6.0, Microsoft Excel 2003.
Previous Topic: how to create the static group on runtime ?
Next Topic: illegal restricted procedure error.
Goto Forum:
  


Current Time: Sat Sep 07 13:21:48 CDT 2024