object has no attribute 'open'

653 views
Skip to first unread message

NGM user

unread,
Dec 15, 2009, 8:04:56 AM12/15/09
to python-excel
Im working with this script since weeks. Until today everything works
fine. I could open, read and modify cells without any problems. since
this morning I receive an error that says:

Traceback (most recent call last):
File "C:\Documents and Settings\USER\Desktop\Code\python
\test_file.py", line 129, in <module>
EX = excel_com(ROOT, module_name, TEST_CHAPTER, TEST_DESCRIPTION,
Scope_defines)
File "C:\Documents and Settings\USER\_resources\libs\excel_lib.py",
line 88, in __init__
self.xlApp.Workbooks.open(r'C:\Documents and Settings\USER
\Testreport\FRT.xlsx')
File "C:\Python31\Lib\site-packages\win32com\client\__init__.py",
line 462, in __getattr__
raise AttributeError("'%s' object has no attribute '%s'" % (repr
(self), attr))
AttributeError: '<win32com.gen_py.Microsoft Excel 12.0 Object
Library.Workbooks instance at 0x16287504>' object has no attribute
'open'

what happened?
whats wrong with my code:

self.xlApp = Dispatch('Excel.Application')
self.xlApp.Visible = 1
self.xlApp.Workbooks.open(r'C:\Documents and Settings\USER\Testreport
\FRT.xlsx') #error here

pls help me!

Chris Withers

unread,
Dec 15, 2009, 8:17:53 AM12/15/09
to python...@googlegroups.com
NGM user wrote:
> self.xlApp = Dispatch('Excel.Application')
> self.xlApp.Visible = 1
> self.xlApp.Workbooks.open(r'C:\Documents and Settings\USER\Testreport
> \FRT.xlsx') #error here

If you're using COM like this, try rebooting the machine this is running on.

I'd recommend taking a look at xlrd/xlwt/xlutils.

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

John Machin

unread,
Dec 15, 2009, 9:02:14 AM12/15/09
to python...@googlegroups.com
On 16/12/2009 12:04 AM, NGM user wrote:

> AttributeError: '<win32com.gen_py.Microsoft Excel 12.0 Object
> Library.Workbooks instance at 0x16287504>' object has no attribute
> 'open'
>
> what happened?
> whats wrong with my code:
>
> self.xlApp = Dispatch('Excel.Application')
> self.xlApp.Visible = 1
> self.xlApp.Workbooks.open(r'C:\Documents and Settings\USER\Testreport
> \FRT.xlsx') #error here

Perhaps the Workbooks object has an attribute named 'Open' ... I'm
pig-ignorant about COM and wish to remain so; however I have some code
that works with ....Workbooks.Open(....) and fails with a very similar
error message if I change it to ....Workbooks.open(....)


geoff_ness

unread,
Dec 16, 2009, 2:58:37 AM12/16/09
to python-excel
Yep, that's it I believe - as the python interpreter is case-
sensitive, it distinguishes between Open (which is a method of the
Workbooks collection object) and open (which isn't). I make this sort
of mistake all the time switching between writing code in python and
VB, where existing attributes are automatically capitalised.
Reply all
Reply to author
Forward
0 new messages