[python-win32] NEWBIE QUESTION - 'NoneType' object has no attribute'ActiveSheet'

Mark Hammond mhammond at skippinet.com.au
Thu Nov 18 05:52:43 CET 2004


>     xlApp.ActiveWorkbook.ActiveSheet.Cells(1).Rows.EntireRow.Delete(1)
> exceptions.AttributeError: 'NoneType' object has no attribute
> 'ActiveSheet'

That is telling you that 'xlApp.ActiveWorkbook' (ie, the object from which
'ActiveSheet' is being requested) is returning None - ie, no workbook is
open.

> My theory is that the object isn't loaded into memory yet on
> first click and
> only gets correctly instantiated AFTER the first click...

I suspect that Excel's startup process is the reason.  It probably gets to a
very early point (ie, no sheets open, but still 'working') when your call to
"Dispatch()" returns.  It is probably after this that Excel does whatever it
is configured to do at startup - generally load a blank worksheet.

For a simple solution, just sleep a brief while.

Mark



More information about the Python-win32 mailing list