I'm struggling to access Python from Excel VBA (which I'm familiar with). There was a very useful answer here (reproduced below). I followed the steps very carefully - the same error occurs whether I'm using Python 3.3 or Python 2.7.
When I use the Command Button to execute the VBA code, it fails at this statement: PyScript.Language = "python" with error message "Run time error 380: A script engine for the specified language cannot be created"
Any ideas please?
The answer from stackoverflow that I'm trying to use follows.
Follow these steps carefully
- Go to Activestate and get [ActivePython 2.5.7][1] MSI installer.
I had DLL hell problems with 2.6.x - Install in your Windows machine
once install is complete open Command Prompt and go to
C:\Python25\lib\site-packages\win32comext\axscript\client
execute
\> python pyscript.pyyou should see message Registered: PythonGo to ms office excel and open worksheet
- Go to Tools > Macros > Visual Basic Editor
- Add a reference to the Microsoft Script control ![alt text][2]
- Add a new User Form. In the UserForm add a CommandButton
Switch to the code editor and Insert the following code
Dim WithEvents PyScript As MSScriptControl.ScriptControl
Private Sub CommandButton1_Click() If PyScript Is Nothing Then Set PyScript = New MSScriptControl.ScriptControl PyScript.Language = "python" PyScript.AddObject "Sheet", Workbooks(1).Sheets(1) PyScript.AllowUI = True End If PyScript.ExecuteStatement "Sheet.cells(1,1).value='Hello'" End Sub
Execute. Enjoy and expand as necessary
PyScript.Language = "Python".ScriptControlonly supportsVBScriptorJScriptmsdn.microsoft.com/en-us/library/aa227400(v=vs.60).aspx, I think you will need to use another method than this. Not sure how it garnered so many upvotes on the other question, but it does not seem to work.