How to end oExcel := TOleAuto():New( "Excel.Application" ) ?

How to end oExcel := TOleAuto():New( "Excel.Application" ) ?

Postby ShumingWang » Sat Apr 24, 2010 6:06 am

Hi,
oExcel := TOleAuto():New( "Excel.Application" )
oExcel:WorkBooks:Open(ALLTRIM(cfile))
oSheet := oExcel:ActiveSheet()
oExcel:quit()

but excel.exe still runnning in memory.
Thanks !
Shuming Wang
http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
ShumingWang
 
Posts: 460
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Re: How to end oExcel := TOleAuto():New( "Excel.Application" ) ?

Postby anserkk » Sat Apr 24, 2010 6:40 am

Dear Mr.Shuming Wang

Your code is working fine for me
Code: Select all  Expand view

#include "fivewin.ch"

FUNCTION MAIN

  cFile:="c:\users\anser\desktop\Test.xls"
  MsgInfo("About to create Excel object")
 
  oExcel := TOleAuto():New( "Excel.Application" )
  oExcel:WorkBooks:Open(ALLTRIM(cfile))
  oSheet := oExcel:ActiveSheet()
 
  MsgInfo("Open and Check Task Manager, you should find EXCEL.EXE in the Processes List")
 
  oExcel:quit()
 
  MsgInfo("Excel is closed. After you close this MsgBox,";
          "you will not find EXCEL.EXE in the Task Manager, Processes List")
   
RETURN NIL


Tested using Office 2007. It is also better to do a oWorkBook:Close() before the oExcel:Quit()

Code: Select all  Expand view
oWorkBook:=oExcel:WorkBooks:Open(ALLTRIM(cfile))
oWorkBook:Close()
oExcel:Quit()
 


I suggest you to check whether any previously opened Excel instances are still running in your PC, may be that could be the reason. :)

While trying to creating the excel object, It is always better to code as given below

Code: Select all  Expand view
TRY
    oExcel = GetActiveObject( "Excel.Application" )
CATCH
    TRY
        oExcel = CreateObject("Excel.Application")
    CATCH
        MsgInfo("It seems that Excel is not installed on this PC. You need Excel to continue further")
        Return .F.
    END
END
 

Regards
Anser
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to end oExcel := TOleAuto():New( "Excel.Application" ) ?

Postby lailton.webmaster » Sat Apr 24, 2010 6:47 pm

It´s work fine to me.

oExcel := TOleAuto():New( "Excel.Application" )
oExcel:WorkBooks:Open(ALLTRIM(cfile))
oSheet := oExcel:ActiveSheet()
oExcel:quit()

oExcel:=Nil
Release All

:D
lailton.webmaster
 
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: How to end oExcel := TOleAuto():New( "Excel.Application" ) ?

Postby Enrico Maria Giordano » Sun Apr 25, 2010 9:44 am

lailton.webmaster wrote: oExcel:quit()

oExcel:=Nil
Release All


oExcel:quit() is more than enough.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 105 guests