[python-win32] COM access to Excel suddenly stopped working

Mark Hammond mhammond at skippinet.com.au
Tue Apr 19 06:52:27 CEST 2005


Hi John,

> (1) xl = win32com.client.Dispatch("Excel.Application")
> (2) print repr(xl)
> (3) xlwb = xl.Workbooks.Open(filename)
>
> Before, line 2 would print this:
> <win32com.gen_py.Microsoft Excel 10.0 Object
> Library._Application instance at
> 0x39073872>
> and line 3 would work OK.
>
> Now, line 2 prints this:
> <COMObject Excel.Application>

That is strange - the script is not finding the makepy generated file.  This
could be due to the gen_py directory being removed - by default you should
find it in lib\site-packages\win32com\gen_py

Using win32com.client.gencache.EnsureDispatch() in place of Dispatch should
force that generation - but I'm afraid I have no idea why it suddenly became
necessary.

Mark



More information about the Python-win32 mailing list