473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

win32com.client problem

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,

--
Me
Jul 18 '05 #1
2 2607
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/...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

Jul 18 '05 #2
Thanks for the reply. I will chew on this a bit.

"Kartic" <ka******************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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/...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

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
3
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
1
by: Cristian Hasbun from Chile | last post by:
I need a win32com guru please... i'm not python expert, but i understand mi trouble... Requirements: Hook EyesWeb 3.2.0 (http://www.eyesweb.org) COM Module with Python 2.0.1 i used win32com...
1
by: Patrick | last post by:
I am investigating a web-based app wherein I wanted to provide html form frontends to an Excel spreadsheet sitting on a MS Windows server; with each authenticated HTTP user having thier own...
0
by: goermezer | last post by:
Hello, I have some problems to automate a CAD (computer aided design) Software called CATIA V5 from Dassault Systemes. CATIA V5 has a builtin VB-Editor like Word, Excel, … and registers itself...
2
by: Sibylle Koczian | last post by:
Hello, I've installed Python 2.4 and the win32 extensions, using administrator rights, under Windows XP in "C:\Programme". As this is a directory without spaces I didn't expect any problems. But...
1
by: koia | last post by:
Hi, I have a problem with adding attributes to a Line in an Excel drawing using the Python win32com interface. From recording in Excel I get the Macro: Sub Makro1()...
3
by: tyler.schlosser | last post by:
Hi there, I am trying to launch a program called AmiBroker using the command: AB = win32com.client.Dispatch("Broker.Application") However, I have a dual-core CPU and would like to launch two...
1
by: SPJ | last post by:
Sorry, forgot to mention Subject in my earlier post, hence reposting. ------------ I am writing a script which need's to convert an excel file to csv (text) format. For that I am using the...
11
by: Bill Davy | last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers from my address book which is an Excel spreadsheet to my mobile phone. I came across the following snippet of code which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.