FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour oExcel:Quit()
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
oExcel:Quit()
Posted: Wed Sep 07, 2016 06: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

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: oExcel:Quit()
Posted: Wed Sep 07, 2016 06: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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: oExcel:Quit()
Posted: Wed Sep 07, 2016 07: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 :-)
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.
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: oExcel:Quit()
Posted: Wed Sep 07, 2016 09: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.

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: oExcel:Quit()
Posted: 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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: oExcel:Quit()
Posted: 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: oExcel:Quit()
Posted: 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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: oExcel:Quit()
Posted: Thu Sep 08, 2016 01: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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: oExcel:Quit()
Posted: Thu Sep 08, 2016 01: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: oExcel:Quit()
Posted: Thu Sep 08, 2016 01:26 PM
Here it is:

Code (fw): Select all Collapse
#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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: oExcel:Quit()
Posted: Thu Sep 08, 2016 01: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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: oExcel:Quit() [ Solved ]
Posted: Thu Sep 08, 2016 08: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

Continue the discussion