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