0

I wrote a Python code that performs some calculations using as input data in an excel workbook. My goal is to add a button inside the input excel workbook that automatically run the python script. I have already added the button to which I've associated the following macro:

'''

Sub RunPythonScript()

    Dim objShel As Object
    Dim PythonExe, PythonScript As String
    
    Set objShell = VBA.CreateObject("Wscript.Shell")
    
    PythonExe = "*path to python.exe*"
    
    PythonScript = """*path to the code*"""
    
    objShell.Run PythonExe & PythonScript

End Sub

'''

The macro isn't working and returns the error Method 'Run' of object IWshShell3 failed! I don't know if the issue is due to the fact that I have the input excel workbook for the python code open (usually should be closed to make the code works).

Kostas K.
  • 8,293
  • 2
  • 22
  • 28
  • Does this answer your question? [How to call python script on excel vba?](https://stackoverflow.com/questions/18135551/how-to-call-python-script-on-excel-vba) – Gangula Aug 24 '21 at 17:25

1 Answers1

0

maybe you can try put that run python command into a bat file then run that bat file

qmhedging
  • 19
  • 3