Calling Excel module functions from python [repost]

Bob Gailer bgailer at alum.rpi.edu
Thu Jul 10 11:28:46 EDT 2003


At 02:42 AM 7/10/2003 -0700, Mark Carter wrote:

>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*

To call a function in a VBA module:

wbc.Run('SaveSheet')


Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.492 / Virus Database: 291 - Release Date: 6/24/2003


More information about the Python-list mailing list