Calling Python Script from MS Excel?

Giles Brown giles_brown at hotmail.com
Tue Jun 8 05:13:46 EDT 2004


"Kevin T. Ryan" <kevryan0701 at yahoo.com> wrote in message news:<40c51309$0$2944$61fed72c at news.rcn.com>...
> Hi Group - 
> 
> I have written a "semi-program" in MS Excel related to running a football
> pool.  I've updated it over the past two years or so, to the point where it
> is getting pretty advanced.  Only, there are a few tricks that I want to
> add that I could not do in Excel - so I did them in Python :)  Except as it
> stands, the current python scripts have to be run via the command line. 
> Does anyone know how to allow interaction between Excel and Python via
> EXCEL?
> 
> I've looked on Mark Hammond's page, and I've figured out how to interact
> with Python and Excel from PYTHON, but I can't seem to find the right info
> for making the calls from the other end (i.e. from Excel).  Any advice
> would be GREATLY appreciated!

One way of approaching this would be to package your Python code 
as a COM server.  This is actually much easier than you might think
(this reference is quite old but is still relevant):

http://www.python.org/windows/win32com/QuickStartServerCom.html

You can make calls on your object from Excel VBA.  For example you
could call on the object in the reference above as:

Dim HelloWorld As Object

Set HelloWorld = CreateObject("testcomserver.HelloWorld")
MsgBox HelloWorld.Hello("Kevin")

Hth,
Giles



More information about the Python-list mailing list