Page 1 of 1

Cannot close Excel with WIN32OLE

Posted: Thu Jan 03, 2008 3:40 pm
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:

Posted: Thu Jan 03, 2008 4:25 pm
by jacquetph
With Fivewin and xharbour, just comment your line oxls:end()
You dont need it anymore .
Good luck

Posted: Thu Jan 03, 2008 5:05 pm
by Gale FORd
I think what you want is

oExcel:quit()
oExcel := nil

Posted: Thu Jan 03, 2008 6:23 pm
by Enrico Maria Giordano
Gale FORd wrote:I think what you want is

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

EMG

Posted: Thu Jan 03, 2008 7:30 pm
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.

End Excel-Worksheet

Posted: Thu Jan 03, 2008 10:00 pm
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:

Posted: Thu Jan 03, 2008 11:16 pm
by Armando
What if you try this way

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


Regards

Posted: Thu Jan 03, 2008 11:30 pm
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

Posted: Thu Jan 03, 2008 11:53 pm
by Gale FORd
I did not believe it either. I will put something together tomorrow.

Posted: Fri Jan 04, 2008 12:31 am
by Enrico Maria Giordano
Ok, thank you. I'm pretty curious...

EMG

Posted: Fri Jan 04, 2008 2:55 pm
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 )


Posted: Fri Jan 04, 2008 3:06 pm
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.

Posted: Fri Jan 04, 2008 4:39 pm
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

Posted: Fri Jan 04, 2008 4:47 pm
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. :)

Posted: Fri Jan 04, 2008 6:04 pm
by Enrico Maria Giordano
Ok, understood.

EMG