Newbie Excel question

Gerhard Häring gerhard.nospam at bigfoot.de
Sun Jan 28 16:58:09 EST 2001


Fabrizio wrote:
> 
> Hi,
> 
> Newbie, Python2.0, Windows 98, Win32-All, MS Excel97.
> 
> Experimenting with Python and Excel, I have found this example on the web :
> 
> [...]
> from win32com.client import Dispatch
> 
> xlApp = Dispatch("Excel.Application")
> xlApp.Visible = 1
> xlApp.Workbooks.Add()
> xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!'
> xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!'
> xlApp.Close(SaveChanges=0)
> xlApp.Quit()
> del xlApp
> 
> If I run it the program opens an Excel sheet, writes something in the cells,
> but it fails to close !
> This is what I get :
> 
> Traceback (innermost last):
>   File "C:\Utili\Programmazione\Python\Programmi\excel.py", line 16, in ?
>     xlApp.Close()
>   File "C:\Python20\win32com\client\dynamic.py", line 435, in __getattr__
>     raise AttributeError, "%s.%s" % (self._username_, attr)
> AttributeError: Excel.Application.Close
> 
> Any help ?

Perhaps. I have Excel 2000 here. The AttributeError just means that
Excel.Application has no Close method. If you want to examine the
methods and attributes available, you can Start Excel, hit Alt-F11 to
get into the Visual Basic editor, then hit F2 to get to the Object
browser. You can then look at the entire Excel object hierarchy to see
which Classes support which methods.

I guess that the above code simply has a typo, it should probably mean
xlApp.ActiveWorkbook.Close(SaveChanges=0). At least this works on my
Excel 2000.

Gerhard
-- 
Sorry for the fake email, please use the real one below to reply.
contact: g e r h a r d @ b i g f o o t . d e
web:     http://highqualdev.com



More information about the Python-list mailing list