[python-win32] excel termination

Tim Golden tim.golden at viacom-outdoor.co.uk
Thu Apr 15 04:32:28 EDT 2004


GA> Thank you for your replies, 
GA> I have tried it but it doesn't work, any other suggestions?

GA> excel=Dispatch("Excel.Application")
GA> [snip code sample]
GA> excel.Quit()
GA> sleep(0.5)
GA> del excel
GA> sleep(0.5)

GA> I have tried longer periods for sleep, 
GA> but this does not help. 
GA> This piece of code is nested in a for 
GA> loop, could that have anything do with it?

As a matter of fact, you shouldn't need the sleep;
if Excel's going to go away, it's going to go away
and you're not bothered when. I used it because I
needed to illustrate programatically when the
Excel process was and wasn't running.

The fact that the code's in a loop shouldn't matter,
although -- depending on exactly what you're doing --
I would have thought that an approach such as this
might have served the purpose slightly better:

<non-working code>

xl = Dispatch ("Excel.Application")

for data in stream_of_data:
  wb = xl.Workbooks.OpenText (blah)
  # do stuff with wb and data
  xl.ActiveWorkbook.Close ()

xl.Quit ()
del xl

</code>

Nonetheless, the Quit and so on should have the
same effect however you do them. To ask an obvious
question, is there any other Excel session open at
the time? (ie are you running Excel as a user
rather than through Python?) 

I can't see anything else which is likely to 
be causing the problem. Can you post a working
code segment which displays the symptoms?

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-win32 mailing list