473,804 Members | 3,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2635
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._GetI nterfaceCount()
print 'Done! Active Com Connections :',ActiveComCon n # 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.co m> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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._GetI nterfaceCount()
print 'Done! Active Com Connections :',ActiveComCon n # 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
5199
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 remove old version (as well as the mx libraries I had installed). I then installed the new version as a user with the Administrator role. I know I'm technically not supposed to install to a directory with a space in the name, but it worked fine for...
3
7028
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 and Word examples run fine. win32com.client.Dispatch("Excel.Application") etc., but how does one know the ("<foo>.<bar>") to type in? Excel looks only vaguely like "Excel.Application" in the com browser.
1
1800
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 libraries and generate an early binding for module (using prog_id)
1
3272
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 "invisible" copy of the spreadsheet changeable via form POST via COM automation object (via Python) - then after recalculating - present the spreadsheet results in HTML. The whole idea to 1: isolate the user from having to have Excel, and 2: avoiding...
0
4128
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 as a COM-server. With VB one can automate everything in CATIA V5 with a lot of registered Object Libraries. A VB example:
2
7102
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 now I can't _use_ win32com as a normal user, because normal users can't write there: PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond@skippinet.com.au) -
1
3727
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() ActiveSheet.Shapes.AddLine(192.75, 63.75, 316.5, 110.25).Select Selection.ShapeRange.Line.ForeColor.SchemeColor = 10 Selection.ShapeRange.Line.Visible = msoTrue
3
6960
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 instances of AmiBroker. I know it is possible to run two instances simultaneously since it is easy to do manually by double-clicking the AmiBroker.exe file twice. However, when I write two lines of code like this:
1
3045
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 following code: excel = win32com.client.Dispatch("Excel.Application","Quit") workbook = excel.Workbooks.Open(xlsfile) workbook.SaveAs(csvfile, FileFormat=24) # 24 represents xlCSVMSDOS workbook.Close(False) excel.Quit()
11
7752
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 enabled me to the contacts at least list. I had to root around to discover CdoDefaultFolderContacts (though it was guessable; how could I enumerate win32com.client.constants?). I now want to work through the Contacts in Outlook patching in...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.