Calling Excel module functions from python [repost]

Mark Carter cartermark46 at ukmail.com
Thu Jul 10 05:42:57 EDT 2003


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*




More information about the Python-list mailing list