Re: Create Macro in Excel with OLE2 [message #451525] |
Thu, 15 April 2010 03:47 ![Go to next message Go to next message](/forum/theme/orafaq/images/down.png) |
annappan
Messages: 2 Registered: April 2010 Location: CHENNAI
|
Junior Member |
|
|
[EDITED by DJM: added reference to original thread]
http://www.orafaq.com/forum/mv/msg/128729/363323/67467/#msg_363323 Hello,
Sorry for the interrupt, which you posted the coding useful and helpful for me, I have one query.
Aim of Program: Create Macro in Excel with OLE2 in ORACLE FORM.
I mention below codingDeclare
application OLE2.OBJ_TYPE;
workbooks OLE2.OBJ_TYPE;
workbook OLE2.OBJ_TYPE;
worksheets OLE2.OBJ_TYPE;
worksheet OLE2.OBJ_TYPE;
WorkFont OLE2.OBJ_TYPE;
vbproject OLE2.OBJ_TYPE;
vbcomponents OLE2.OBJ_TYPE;
item OLE2.OBJ_TYPE;
codemodule OLE2.OBJ_TYPE;
args OLE2.LIST_TYPE;
args1 OLE2.LIST_TYPE;
cell OLE2.OBJ_TYPE;
V_str varchar2(4000);
BEGIN
Application:=OLE2.CREATE_OBJ('Excel.Application');
OLE2.Set_Property(application,'Visible', 'True');
workbooks:=OLE2.GET_OBJ_PROPERTY( application, 'Workbooks' );
workbook:=OLE2.INVOKE_OBJ(workbooks, 'Add');
vbproject:=ole2.get_obj_property(workbook,'VBProject');
vbcomponents:=ole2.get_obj_property(vbproject,'VBComponents');
args := ole2.create_arglist;
ole2.add_arg(args,1);
codemodule:=ole2.invoke_obj(vbcomponents, 'Add', args);
OLE2.DESTROY_ARGLIST(args);
args := ole2.create_arglist;
--Macro--
ole2.add_arg(args,'
Private Sub Workbook_Open()
On Error Resume Next
Dim xmlfile As String
Dim xlsfile As String
xmlfile = XMLtoExcel.Cells(1, 1)
xlsfile = XMLtoExcel.Cells(2, 1)
If Len(xmlfile) = 0 And Len(xlsfile) = 0 Then
End
Else
XMLtoExcel.Cells(1, 1) = ""
XMLtoExcel.Cells(2, 1) = ""
ActiveWorkbook.Save
Workbooks.OpenXML Filename:=xmlfile, Stylesheets:=Array(1)
ActiveWorkbook.SaveAs Filename:=xlsfile, FileFormat:=xlNormal _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Save
End If
End Sub');
--Macro--
oLE2.Set_Property(workbook, 'AddFromString',args);
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 'D:\Temp\xls\Excel2.xls');
OLE2.INVOKE(workbook,'SaveAs',args);
OLE2.INVOKE(application,'Quit');
OLE2.RELEASE_OBJ(workbook);
OLE2.RELEASE_OBJ(workbooks);
OLE2.RELEASE_OBJ(application);
END; In the code creating excel file but not create the macro, I didn't get any error message.
Could you please tell me, what the reason? [EDITED by DJM: add code tags]
[Updated on: Thu, 15 April 2010 20:18] by Moderator Report message to a moderator
|
|
|
|
|