Calling Excel module functions from python [repost]
Koczian
Sibylle.Koczian at Bibliothek.Uni-Augsburg.de
Thu Jul 10 08:56:35 EDT 2003
Mark Carter schrieb:
> In Excel, I have a module named modCSV which has a function named
> SaveSheet(), which I want to be able to call from python. How do I do
> it?
>
> I've opened the workbook containing the module, and executed the code:
>
> from win32com.client import Dispatch
> xlApp = Dispatch("Excel.Application")
> xlApp.Visible = 1
> wb = xlApp.ActiveWorkbook
> wbc = wb.VBProject.VBComponents("modCSV")
> wbc.SaveSheet()
>
> but I get the error message:
>
> Traceback (most recent call last):
> File "C:\Documents and Settings\mcarter\My
> Documents\cvs-tree\project\2195\code\temp.py", line 17, in ?
> wbc.SaveSheet()
> File "C:\Python22\lib\site-packages\win32com\client\dynamic.py",
> line 454, in __getattr__
> raise AttributeError, "%s.%s" % (self._username_, attr)
> AttributeError: <unknown>.SaveSheet
>
> It apparently likes the line wbc = ... , but then hates
> wbc.SaveSheet(). *Sigh*
Try
xlApp.Run('SaveSheet')
That works with ordinary Excel macros, but I don't know about
VBProject.VBComponents. Possibly this might work:
wbc.Run('SaveSheet').
HTH,
Koczian
--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Sibylle.Koczian at Bibliothek.Uni-Augsburg.DE
More information about the Python-list
mailing list