win32com.client problem

I

It's me

I've been using the win32com module with very good success in placing data
onto an Excel spreadsheet. However, whenever I have an error in my script
(like mapping a non-square array onto the spreadsheet), something breaks.
After fixing my error and restart the Python program again, Excel would
start up a window with a "Microsoft Excel - BookX" where X is a increasing
number (1,2,3,4,....) instead of just 1. Then, the spreadsheet portion of
the screen is hidden - I can only see the menu bars (on top).

If I restart the computer, run the Python script again and Excel would
behave fine and it would start with "Microsoft Excel - Book1" everytime.

My guess is that there is a zombie Excel process that got stuck in the
system. However I couldn't tell for sure by looking at the Process Manager
list.

Any idea how I can prevent this?

Thanks,
 
K

Kartic

Hi,

1. Put your COM invokations in a try/except loop. From my experience,
that helped me prevent, in most cases, Excel from "hanging" and having
to restart the PC too. In the except part, release the Excel (or other
COM resource) (e.g.calling workbook.Close() or excelobj.Quit(),
depending on the state of your program)

2. Look at
http://www.faqts.com/knowledge_base/entry/versions/index.phtml?aid=5847
to see how to get the actual error.

3. Delete instances of the COM connection, RS object or whatever
win32com.client instances you create. I do this:
sheetobj = None
wbkbobj = None
excelobj = None
del sheetobj
del wbkobj
del excelobj

4. At the end of my scripts, I do the following during the development
stage:
ActiveComConn = pythoncom._GetInterfaceCount()
print 'Done! Active Com Connections :',ActiveComConn # Print count of
Active COM connections.

Thank you,
--Kartic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top