Python in Excel

Ajith Prasad ofnap at nus.edu.sg
Fri Jul 11 17:16:33 CEST 2003


This looks very useful to Excel users who would like to tap the power
of Python. However, not knowing enough about VBA syntax it was not
possible to  proceed beyond step(a). Is it possible to provide an
Idiot's guide to steps (b), (c),(d) and (e)? In other words, what is
the explicit VBA code/steps need to do (b) and (c) and could simple
(even trivial) examples be given of steps (d) and (e). Thanks in
advance.


hannibal <hannibal1812 at canada.com> wrote in message news:<be5amo$2phm$1 at adenine.netfront.net>...
> You can use Microsoft Script Control. If you have the win32 extensions 
> of python, you can use python in place of vb in this control
> 
> -(a)open the VBA script editor - In menus/Tools/References add Microsoft 
> Script Control
> -(b)Make a new module and declare a new MsScriptControl.ScriptControl
> 	Global sc as new MsScriptControl.ScriptControl
> -(c)Initialize the language attibute with python - Note that you and users 
> of your document must have python and its win32 extensions installed. 
> Activestate python distribustion include it.
> You can put
> 	sc.language="python"
> in the routine Workbook_Open()
> 
> (d)Now you can import python modules using ExecuteStatement method of the 
> control in vba and have results from python functions with eval method. 
> (e)One interesting thing is that you can pass an object to the control with 
> AddObject method and have python manipulate it. And so on..
> 
> 
> 
> John J. Lee a écrit :
> > "Tom Locke" <tom at liveDELETE-MElogix.com> writes:
> > 
> > 
> >>>>Can I write Excel macros/scripts using Python?
> >>>>
> >>>>I mean to actually put Python into an Excel document, not using
> >>>>Python to access data, for example, from some Excel document.
> >>
> >>These days you can script office with any .NET language, and that includes
> >>Python:
> > 
> > [...]
> > 
> > Or use good old COM.  There's an example of controlling Excel (the
> > version from Office 2000) in the Python for Windows Extensions (aka
> > win32all) COM test code.  IIRC, it'll be somewhere like
> > C:\Python\win32com\tests\.
> > 
> > 
> > John
> 
> ---
> Posted via news://freenews.netfront.net
> Complaints to news at netfront.net




More information about the Python-list mailing list