Python in Excel

hannibal hannibal1812 at canada.com
Sat Jul 5 03:48:15 CEST 2003


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

-open the VBA script editor - In menus/Tools/References add Microsoft 
Script Control
-Make a new module and declare a new MsScriptControl.ScriptControl
	Global sc as new MsScriptControl.ScriptControl
-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()

Now you can import python modules using ExecuteStatement method of the 
control in vba and have results from python functions with eval method. 
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