COM - Excel: What happens if users closes workbook externally?

M

Marc

Hi all,

I have a problem with managing the interchange between COM/Excel and
Python if the user closes the workbook externally.

Everything works fine as long as the user only uses the exit keys I've
provided to close the Excel apps and COM interfaces. But I really need
the ability to manage the workbook if someone closes it using the
'exit' command or the right/upper 'x' from within the excel
spreadsheet.

When that happens, the workbook is lost, but the interface between
python and the COM server stays open. So when I go back later and try
to update the sheet, of course it's not there. But I don't know how to
monitor the status of the workbook to see if I need to create another
one or use the initial one.

I've tried different ways of checking to see if the workbook is still
active, but nothing has worked. Is there anyway to bind the 'exit' and
'x' from the excel spreadsheet to functions within my python script so
that I'll know when the workbook is closed? Or is there a better way
to handle this scenario. Unfortunately, simply telling them not to do
it that way is not an option.

Thanks ahead of time,
Marc
 
A

Andrew Dalke

Marc
Anyone? Really need to figure this out.

On the theory that a wrong answer will bring responses from people
who actually know the answer ...

There should be a way to receive the close window event. There
is a test file in the win32 distribution named 'testMSOfficeEvents.py'
which has handlers like

def OnQuit(self):
self.seen_events["OnQuit"] = None
stopEvent.set()

Given some of the other events in that file I found

http://www.as-ltd.co.uk/xllplus-online/CXllApp_Methods.htm

which suggests you should look at the OnWorkbookBeforeClose
event.

Hope that helped.

Andrew
(e-mail address removed)
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top