Home » Developer & Programmer » Forms » Re: Create Macro in Excel with OLE2
Re: Create Macro in Excel with OLE2 [message #451525] Thu, 15 April 2010 03:47 Go to next message
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 coding
Declare
	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

Re: Create Macro in Excel with OLE2 [message #451635 is a reply to message #451525] Thu, 15 April 2010 20:20 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Do NOT hijack old threads!

Use 'code' tags!

Is this your first form?

Place 'message; pause;' pairs between the commands and determine the line that is failing.

David
Re: Create Macro in Excel with OLE2 [message #452088 is a reply to message #451635] Tue, 20 April 2010 00:04 Go to previous message
annappan
Messages: 2
Registered: April 2010
Location: CHENNAI
Junior Member
Sorry David.
Previous Topic: how to use Java instead Jinitiator
Next Topic: Auto refresh when data updated
Goto Forum:
  


Current Time: Fri Sep 20 09:26:46 CDT 2024