Calling Excel module functions from python [repost]

Mark Carter cartermark46 at ukmail.com
Thu Jul 10 12:37:07 EDT 2003


Koczian <Sibylle.Koczian at Bibliothek.Uni-Augsburg.de> wrote in message news:<bejgq8$9j8$1 at rzmux02.rz.uni-augsburg.de>...
> 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:
[snip]

> Try
> 
> xlApp.Run('SaveSheet')

It works!


> That works with ordinary Excel macros, but I don't know about 
> VBProject.VBComponents. Possibly this might work:
> 
> wbc.Run('SaveSheet').

It doesn't work. But that doesn't matter, because the first method works.

A further tip:
For a function taking arguments, use
xlApp.Run("func", "arg1", "arg2", ...)

Thanks




More information about the Python-list mailing list