Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel won't quit using ole2 method

Status
Not open for further replies.

housemania

Programmer
Jul 30, 2004
1
NL
Hi,

I'm using the forms package ole2 to quit ms-excel with a command like this:
OLE2.SET_PROPERTY(i_application, 'DisplayAlerts', 0);
ole2.invoke (i_application, 'Quit');
On my desktop excel disappears, however in the taskmanager there is still a process excel.exe, so in fact excel is still running, but on the background.
How can I make excel really quit?
('quit' works fine for ms-word)

Cheers, Arjen Huisman
 
Hi,
An Orphan Object Handle is causing the problem. Releasing OBJ after OLE2.SET_PROPERTY(......) will do the trick.

Have a look at following sample code:
Code:
PROCEDURE test_proc IS   
application    OLE2.OBJ_TYPE;   
workbooks      OLE2.OBJ_TYPE;   
workbook       OLE2.OBJ_TYPE;   
worksheets OLE2.OBJ_TYPE;   
worksheet      OLE2.OBJ_TYPE;   
cell           OLE2.OBJ_TYPE;   
args           OLE2.LIST_TYPE; 
BEGIN 
--   updt_file;    
application := OLE2.CREATE_OBJ('Excel.Application');    workbooks := OLE2.GET_OBJ_PROPERTY(application, 'Workbooks');    
workbook  := OLE2.GET_OBJ_PROPERTY(workbooks, 'Add');    worksheets := OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');    
worksheet  := OLE2.GET_OBJ_PROPERTY(worksheets, 'Add');           
args := OLE2.CREATE_ARGLIST;     
OLE2.ADD_ARG(args,3);            
OLE2.ADD_ARG(args,5);            
cell := OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args);    OLE2.DESTROY_ARGLIST(args);  
OLE2.SET_PROPERTY(cell,'Value', 'Well Done');  --Releasing Object handle Cell.     
OLE2.RELEASE_OBJ(cell);     
args := OLE2.CREATE_ARGLIST;    
OLE2.ADD_ARG(args,4);    
OLE2.ADD_ARG(args,6);    
cell := OLE2.GET_OBJ_PROPERTY(worksheet, 'Cells', args);    

OLE2.DESTROY_ARGLIST(args);     
OLE2.SET_PROPERTY(cell, 'Value', 'Keep it up'); --Releasing Object handle Cell.    
OLE2.RELEASE_OBJ(cell);     
args := OLE2.CREATE_ARGLIST;    
OLE2.ADD_ARG(args, 'C:\TEST.XLS');    
OLE2.INVOKE(workbook, 'SaveAs', args);    OLE2.DESTROY_ARGLIST(args);     
OLE2.INVOKE(application, 'Quit');    
OLE2.RELEASE_OBJ(worksheet);    
OLE2.RELEASE_OBJ(worksheets);  
OLE2.RELEASE_OBJ(workbook);    
OLE2.RELEASE_OBJ(workbooks);    
OLE2.RELEASE_OBJ(application); 

END;

HTH
Regards
Himanshu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top