1

I am pretty new to this. I am trying to get a python script to run through excel I need to use excel because that is what the people I work with understand. I'm stuck because my python script works but I can't get it to work in VBA ideally I need it to run as a function one that I can run on a nearby cell just like any other formula.

my python script is pretty basic and just returns one output for every input.

I know this won't do what I need it to do but I'm not sure why it just pops up the command window and doesn't do anything else.

Sub runpython()

Dim objShell As Object
Dim PythonExe, PythonScript As String

    Set objShell = VBA.CreateObject("Wscript.Shell")

    PythonExe = """C:\Program Files (x86)\Python38-32\python.exe"""
    PythonScript = """Python path"""

    objShell.Run PythonExe & PythonScript

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • The question has been asked before: 1. [How to call python script on excel vba?](https://stackoverflow.com/questions/18135551/how-to-call-python-script-on-excel-vba), 2. [Is there a way to call a Python code in Excel-VBA?](https://stackoverflow.com/questions/45410316/is-there-a-way-to-call-a-python-code-in-excel-vba), 3. [Running a python script from VBA](https://stackoverflow.com/questions/48060097/running-a-python-script-from-vba), 4. [Call Python Script from VBA](https://stackoverflow.com/questions/50805511/call-python-script-from-vba). – Toddleson May 18 '21 at 18:06
  • One more example that focuses on returning a value from the python script: [Return result from Python to Vba](https://stackoverflow.com/a/39517658/14608750) – Toddleson May 18 '21 at 18:10
  • What's in your Python script file? You say it "returns one output for every input", but what are the inputs? – Tim Williams May 18 '21 at 18:22
  • Inputs are a string about 30 characters long, the python file is just a series of if statements that return different options based on the character in different positions. – Jason Snook May 19 '21 at 13:32

0 Answers0