2

There seems to be a lot of threads on this one and they all point to this solution:

Function call_py()

Dim rv As Variant
Const pypath = "C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe "
Const scriptpath = "c:\Users\user\Desktop\test.py"

    rv = Shell(pypath & scriptpath, vbNormalFocus)


End Function

or something similar. All this does though is make a shell pop up and disappear without executing the script. What am I doing wrong?

P.

1
  • 1
    If I were you, I would write those commands in a batch file, and then run the batch file. Commented Aug 3, 2017 at 16:21

2 Answers 2

1

Try this:

Sub bat()
Dim batch, fso As Object
Dim path As String
path = "c:\Users\user\Desktop\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set batch = fso.CreateTextFile(path & "python.bat", True)
batch.writeline "cd " & path
batch.writeline "python test.py"
batch.Close

Shell path & "python.bat", 1
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome Tehscript!! I've been looking for this.
0

Add the argument "-i" to inspect the execution.

The console will remain opened and you'll be able to see why it's not working as expected :

Shell "python -i " & scriptpath

And make sure that the paths are quoted if they contain a space character.

1 Comment

Ha ha! This was going to be my next question! Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.