oExcel:Quit()

oExcel:Quit()

Postby Rick Lipkin » Wed Sep 07, 2016 6:36 pm

To All

I use Ole to create excel files and when I finish .. I always close Excel with oExcel:Quit() .. unfortunately if I open the task manager I still see Excel running as an open task. When I quit my application .. the Excel task closes.

What am I missing to make sure Excel close and not linger as an open process?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2663
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: oExcel:Quit()

Postby cnavarro » Wed Sep 07, 2016 6:52 pm

Try

oBook:Close()
oExcel:Quit()
oExcel := Nil
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: oExcel:Quit()

Postby ukoenig » Wed Sep 07, 2016 7:00 pm

Another solution forces EXCEL to be closed ( or define any other app )

WINEXEC( "taskkill /F /IM EXCEL.EXE"

call taskkill /? to get the parameters

regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: oExcel:Quit()

Postby Gale FORd » Wed Sep 07, 2016 9:51 pm

One of the problems is If there is an Excel error or prompt you might loose control of the excel connection.
Sometime I turn on the visibility so I can see if there are any messages from Excel program.
Also before trying to create a file from excel, I have started checking for the (.xlsx) files existence and deleting it .
That way if i cannot delete it I know it is still open from a prior or current Excel session. It's things like that makes it harder to automate ole tasks.
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: oExcel:Quit()

Postby cnavarro » Thu Sep 08, 2016 12:19 am

Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: oExcel:Quit()

Postby Enrico Maria Giordano » Thu Sep 08, 2016 11:54 am

Rick Lipkin wrote:To All

I use Ole to create excel files and when I finish .. I always close Excel with oExcel:Quit() .. unfortunately if I open the task manager I still see Excel running as an open task. When I quit my application .. the Excel task closes.

What am I missing to make sure Excel close and not linger as an open process?

Thanks
Rick Lipkin


Can I see a sample (better if compilable and runnable) of your code?

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

Re: oExcel:Quit()

Postby nageswaragunupudi » Thu Sep 08, 2016 12:14 pm

cnavarro wrote:Try

oBook:Close()
oExcel:Quit()
oExcel := Nil

Mr Cristobal's advice works for me.
After oExcel := nil, the excel goes out of memory.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: oExcel:Quit()

Postby Enrico Maria Giordano » Thu Sep 08, 2016 1:01 pm

nageswaragunupudi wrote:
cnavarro wrote:Try

oBook:Close()
oExcel:Quit()
oExcel := Nil

Mr Cristobal's advice works for me.
After oExcel := nil, the excel goes out of memory.


It is only needed if oExcel is a static, public or private variable. I recommend to use a local variable instead.

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

Re: oExcel:Quit()

Postby cnavarro » Thu Sep 08, 2016 1:06 pm

Enrico, Please, you can put a small example using a local variable?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: oExcel:Quit()

Postby Enrico Maria Giordano » Thu Sep 08, 2016 1:26 pm

Here it is:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oExcel, oSheet

    oExcel = CREATEOBJECT( "Excel.Application" )

    oExcel:WorkBooks:Add()

    oSheet = oExcel:ActiveSheet

    oSheet:Cells( 1, 1 ):Value = "This is a test"

    oSheet:SaveAs( CURDRIVE() + ":\" + CURDIR() + "\ThisIsATest.xlsx" )

    oExcel:Quit()

    RETURN NIL


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

Re: oExcel:Quit()

Postby cnavarro » Thu Sep 08, 2016 1:38 pm

Ah !, Ok, I understand, only in the event that Excel does not remain open
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: oExcel:Quit() [ Solved ]

Postby Rick Lipkin » Thu Sep 08, 2016 8:16 pm

To All

I have been updating some old code especially where all variables are defined Static at the top of the reports .. part of the code upgrade was to remove all the Statics and use Local's instead. In many cases oExcel was not defined at all ( as in this case ) .. Once I re-defined oExcel and oSheet as local to my Excel file extraction, Excel now un-loads from memory with oExcel:Quit()

Sorry for such a stupid error, however .. I now will go back and look at all my reports and make sure the Static to Local variable conversion makes sure oExcel and oSheet are defined and defined Local to each report module.

Thanks for everyone's input ..

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2663
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 54 guests