I have an interesting problem that I encountered where I can easily use python code from VB in an excel instance as described here: Calling a python script from excel / VBA
However, when I simulate the same code structure in visual studio on the form, the line pyscript.language = "python" fails. Does anyone know if MSScriptControl.ScriptControl can be used in VB.Net to control python, as you can in excel? This would be much simpler than creating a COM object for my python scripts.
Code example (add microsoft script control 1.0 and excel object library):
Imports Microsoft.Office.Interop
Public Class Form1
Dim WithEvents PyScript As MSScriptControl.ScriptControl
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As New Excel.Application
xlApp.Visible = True
Dim xlwbook As Excel.Workbook = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet)
Dim xlSheet As Excel.Worksheet = CType(xlwbook.Worksheets(1), Excel.Worksheet)
If PyScript Is Nothing Then
PyScript = New MSScriptControl.ScriptControl
PyScript.Language = "python"
PyScript.AddObject("Sheet", xlSheet)
PyScript.AllowUI = True
End If
PyScript.ExecuteStatement("Sheet.cells(1,1).value='Hello'")
End Sub
End Class
source
share