I want to develop a tool where it is necessary to start a Python script via VBA.
I found the following code on the internet:
Sub RunPythonScript() '''This sub starts the Python script that creates the plots
Dim objShell As Object
ActiveWorkbook.Save
Dim PythonExePath, PythonScriptPath As String
Set objShell = VBA.CreateObject("Wscript.Shell")
'PythonExePath = """C:\Users\MyName\AppData\Local\Programs\Python\Python38-32\python.exe""" '
PythonScriptPath = "C:\Projects\MYproject\cttdb_plot_creator.py"
objShell.Run PythonExePath & PythonScriptPath
End Sub
This code works for me. However, when a colleague starts the tool from his computer, it does not work.
I think that I have entered too specific a path for "PythonExePath", namely: C:\Users\MyName\AppData\Local\Programs\Python\Python38-32\python.exe.
Is there a way to enter a path that is more general and works for every user?
