Cannot close Excel with WIN32OLE

Post Reply
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Cannot close Excel with WIN32OLE

Post by ukoenig »

Is there anybody who knows,
what i can do to close Excel ?
With the old TAutoOle : oExcel:End() it was ok.
Antonio told me : oExcel := NIL.
It is not working, because in the Filemanager
Excel is still visible and not closed.

Regards U.König :lol:
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.
jacquetph
Posts: 2
Joined: Sat Sep 08, 2007 1:47 pm

Post by jacquetph »

With Fivewin and xharbour, just comment your line oxls:end()
You dont need it anymore .
Good luck
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I think what you want is

oExcel:quit()
oExcel := nil
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Gale FORd wrote:I think what you want is

oExcel:quit()
oExcel := nil
The last is not needed.

EMG
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I thought the same as you, but after helping someone with an Excel problem we found that Excel will still be running even though you cannot see it.

Running the task manager after doing the oExcel:quit() shows that Excel would still be resident until the variable was set to nil.
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

End Excel-Worksheet

Post by ukoenig »

oExcel:Quit()
oExcel := NIL

works fine.
but it creates the worksheet in the background.

I tried to do nothing on the end.
It works also, but with the difference : Excel shows the sheet
and stays open.
I have to close excel with the button ( because I want to check the sheet )
A Test with the Taskmanager shows, that Excel is closed.

Thank you
U. König :lol:
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
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Post by Armando »

What if you try this way

oExcel:WorkBooks:Close()
oExcel:Quit()


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Gale FORd wrote:I thought the same as you, but after helping someone with an Excel problem we found that Excel will still be running even though you cannot see it.

Running the task manager after doing the oExcel:quit() shows that Excel would still be resident until the variable was set to nil.
This is definitely not true. Please, show a sample to demonstrate the problem.

EMG
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I did not believe it either. I will put something together tomorrow.
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I went back and looked at my test prg's and I could not find the one in question so I created one. At first it worked like you said and what I thought originally. Then I got to thinking about how this problem came up. Then I recall that the problem showed up when the function was still running or the variable was a static.

Code: Select all

FUNCTION MAIN()
   LOCAL lRunTest := .t.
   LOCAL oExcel, oSheet
   clear screen
   do while lRunTest
      @ 10, 0 say 'Run Excel Test ' get lRunTest picture 'y'
      read
      if lastkey() = 27
         exit
      endif
      if lRunTest
         @ 20, 0
         // This does not work
         // even though you tell excel to quit it is still
         // running until variable gets reset.
         oExcel = CREATEOBJECT( "Excel.Application" )
         oExcel:quit()
         @ 20, 0 say 'Ok now check with Task Manager'
         wait
         // Works if you run in function that releases variable
         // or you release variable yourself
         oExcel := nil
         TestExcel()
         @ 20, 0 clear
         @ 20, 0 say 'Ok now check Task Manager again'
      endif
   enddo
RETURN( nil )

FUNCTION TestExcel()
   LOCAL oExcel, oSheet
   oExcel = CREATEOBJECT( "Excel.Application" )
   oExcel:quit()
RETURN( nil )

Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I forgot to mention that when you check in the task manager, you have to look under the Processs tab. It is not in the Applications tab.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

This is perfectly normal as the automatic destructor is called when the variable exits the scope. It's not a problem at all.

EMG
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

It was a problem for the person I was helping some time ago because he was using a prg wide static variable. The person in this thread mentioned that Excel was still running so without seeing how he was using the variable I wanted to make sure the variable lost the connection with Excel.

Have a great day. :)
Post Reply