I have Python code that creates an image (jpg format). This code works in Jupyter and Visual Studio code.
I'm trying to execute the code from the Excel workbook that the code imports the data. The idea is to have a button in the Excel workbook to execute the Python code and obtain the image.
Code to execute the Python code in VBA:
Sub RunPythonScript_1()
Dim objShell As Object
Dim PythonExePath, PythonScriptPath As String
Set objShell = VBA.CreateObject("Wscript.Shell")
PythonExePath = """C:\Users\227871\AppData\Local\Microsoft\WindowsApps\python.exe"""
PythonScriptPath = """C:\Users\227871\OneDrive - Weir Group PLC\Francisca\Mejora App Weir\Balance\Balance Collahuasi\Balance 1.py"""
objShell.Run PythonExePath & PythonScriptPath
End Sub
It doesn't show me errors. It appears in the console for one second and closes.
I expect that when I use the button in the Excel workbook, an image appears.
objShell.Run PythonExePath & " -c ""import os;print(os.getcwd());input()"""