0

I'm having trouble finding many resources, but I'm trying to get vba to run a python script

Const pyScript = "C:\Test\Weekend_Exceptions\Weekend_Exception.py"
Dim dblRetVal As Double
dblRetVal = Shell("C:\Python34\python.exe " & pyScript)

I know my python script works and should output a file, but its not. Additionally the vba is not tirggering a debug flag so I'm not sure where I am wrong. Any advice would be appreciated.

2 Answers 2

4

You don't give too much details so i'll make some assumptions

Probably your python script read some local file this will cause your script to raise a FileNotFoundError and exit

To make the test copy the entire arg string to Shell, in your case "C:\Python34\python.exe C:\Test\Weekend_Exceptions\Weekend_Exception.py", open a cmd with Win+r , paste and run, not being in the right directory should raise the same error.

If this is the problem, make a makestuff.bat file with the code

@echo off
@cd C:\Test\Weekend_Exceptions\
@C:\Python34\python.exe Weekend_Exception.py
@echo on

Then call the bat from Shell("C:\Place\of\your\bat\makestuff.bat")

Return with more details to we work on a solution

Sign up to request clarification or add additional context in comments.

Comments

0

Here is how I did:

  1. I created a File1.bat to open the File2.py. The code in File1.bat is:
@echo off
@h:
@cd H:\Path\Cronus\Rangers
@C:\Python3\python.exe File2.py
@echo on

Note that File2.py is inside H:\Path\Cronus\Rangers folder. That's why we need to open it before.

  1. I created a function in VBA to open a .bat file:
Option Compare Database

Function MacroPythonSARH()
On Error GoTo MacroPythonSARH_Err

Call Shell("H:\Path\Cronus\Rangers\File1.bat", 1)

MacroPythonSARH_Exit:
    Exit Function

MacroPythonSARH_Err:
    MsgBox Error$
    Resume MacroPythonSARH_Exit

End Function

Comments

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.