[python-win32] Grabbing an active Excel application
Blair Hall
b.hall@irl.cri.nz
Thu, 15 Aug 2002 15:53:45 +1200
Further to my posting yesterday, and Jens' suggestion, I find that 'grabbing'
an existing Excel is still problematic.
Here is __init__ from my class that wants to use Excel
def __init__(self
, visible=1
):
"""
Create a new file in the current working directory
and save a new Excel workbook in it.
"""
try:
self.__app = win32com.client.Dispatch("Excel.Application")
self.__app.Visible = visible
except pythoncom.com_error, e:
self.__comExceptionHandler(e)
When I instantiate that class the first time, then all
is fine. ie:
>>> xl = myClass()
However, if I then immediately do something silly like
>>> xl = myClass()
Excel disappears from view (it is still running though). From that point
on Python and Excel don't seem to be quite able to agree on how
to interact.
It seems that Jens' suggestion is fine, but in case I am looking for
a few more idiot-proof safeguards.
By the way, I am working on Win95.