[Tutor] RE: [python-win32] Win32com/Excel

Mark Hammond mhammond@skippinet.com.au
Wed, 12 Jun 2002 13:08:24 +1000


> I try to open Excel thru win32com. I write:
> >>>from win32com.client import Dispatch
> >>>xlApp = Dispatch("Excel.Application")
> >>>xlApp.Visible = 1
>
> I get the frame of Excel, but not the spreadsheet. Even if I write:
> >>>xlApp.Workbooks.Add()
> it doesn't give me the ability to look whats there. I get the
> frame around
> the spreadsheet, and the menues at the top, as well as the paperclip. The
> paperclip works, the menus are selectable, but does not work. And
> the space
> where the spreadsheet should have been gives me a "picture" of what is on
> the desktop. (Other open windows in the background and so forth).
> I can move
> the Excel frame around, and the background follows along. I use
> the newest
> version of both Python and Win32com, and have tried this on two
> computers. 1
> with Win98 and 1 with win2k. Same result... Anyone seen this before? And
> managed to solve it?

On my machine, your code seems to work fine - excel repaints and is fully
responsive.  The new worksheet is created and can be interacted with.

This occasionally happens when an existing Excel instance is already
running.  If your program crashed the last time you ran it, you may need to
kill the Excel.exe process manually.

If you see this behaviour inside a more complex app only, then it may be
that you need to occasionally pump a message loop -
pythoncom.PumpWaitingMessages() is often suitable.

Mark.