Running Python scripts from MS Office

Installed PythonWin installed. I can read and write in Excel with Python, not a problem. Not the use I need. All the examples I found are more complex than I need. Since I'm leaving Excel, I need to go through half the steps for testing.

The easiest way to run python scripts from Excel. I do not need gui. Usage: when opening xls excute python script. Nothing special.

Now I just run the scripts manually before opening xls.

Private Sub Workbook_Open()

MyPythonScript.pyw ' this is where scripts should go. just one is all I need. 

End Sub
+3
source share
1 answer

You can use the Excel function Shell, for example.

Sub RunExternalProg()

    Dim return_value As Double
    return_value = Shell("C:\Python26\pythonw.exe C:\my_script.py", vbHide)
    Debug.Print return_value

End Sub

pythonw; .

* Shell Variant (Double) , .

+3

Source: https://habr.com/ru/post/1767028/


All Articles