[python-win32] NEWBIE QUESTION - 'NoneType' object has no attribute
'ActiveSheet'
Kenley _
fission6 at hotmail.com
Thu Nov 18 04:19:47 CET 2004
Thanks for the lucid response Tim. I nixed the import statements; however,
Excel still only flashes on first click of the button.
The debug trace collector shows this on first click:
>>
OnStartupComplete None
pythoncom error: Python error invoking COM method.
Traceback (most recent call last):
File "D:\Python23\Lib\site-packages\win32com\server\policy.py", line 283,
in _Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "D:\Python23\Lib\site-packages\win32com\server\policy.py", line 288,
in _invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "D:\Python23\Lib\site-packages\win32com\server\policy.py", line 581,
in _invokeex_
return func(*args)
File
"D:\Python23\Lib\site-packages\Pythonwin\CheckSymAnalyzer\excelAddin_test.py",
line 71, in OnClick
xlApp.ActiveWorkbook.ActiveSheet.Cells(1).Rows.EntireRow.Delete(1)
exceptions.AttributeError: 'NoneType' object has no attribute 'ActiveSheet'
<<
And then it runs correctly on second click:
>>
OnBeginShutdown None
OnDisconnection
OnBeginShutdown None
OnDisconnection
<<
My theory is that the object isn't loaded into memory yet on first click and
only gets correctly instantiated AFTER the first click... Which allows it to
work the second time around.
I have been trying to figure out how to preload the object into memory which
is what caused my futile attempts with the import statement (Excel as
xlApp). I've gone through Mark Hammond's book (and love it) but I'm just
missing a key detail somewhere.
Thoughts?
More information about the Python-win32
mailing list