Run Python method with args from VBA? (1 Viewer)

pheidlauf

Registered User.
Local time
Yesterday, 22:24
Joined
Jun 5, 2013
Messages
42
I have a python script "runAll" that takes two arguments: processID (the primary key of one table as a string) and a filename (a full file name path as a string).

Is it possible to run a python method with arguments from inside a VBA script (activated by a button press)? If so, could you please provide a generic example of what the code would look like?

My python script is called XMLGenerator.py, and the method I want to run is called runAll(processID,filename).
 

vbaInet

AWF VIP
Local time
Today, 03:24
Joined
Jan 22, 2010
Messages
26,374
As with all scripting languages you can run a function from command line so first of all go to command line and run the script. Once you're successful with that, use the same command line switches and call it using the Shell() function from within Access.
 

pheidlauf

Registered User.
Local time
Yesterday, 22:24
Joined
Jun 5, 2013
Messages
42
I think that the Shell command is definitely the right idea. I have a batch file (shown below) that opens the file I need, but I want to run that straight from the shell command without needing the batch file.

Code:
ssh user@hostname python /home1/username/Projects/importantScript.py ARG & pause
The value "ARG" will be determined by the currently viewed record in the MS Access database, which is accessed in VBA as "Me.processID". The "& pause" is in the bat file simply for testing purposes.

I've tried pasting this into a VBA method as:

Code:
Call Shell("ssh user@hostname python /home1/username/Projects/importantScript.py " & Me.processID & " & pause")

However, this VBA method does not work. What should I do to make this work? Is it possible? If not, what would be the next best way of solving this problem? Outside of VBA I have no idea how to feed an argument into a batch file.
 

spikepl

Eledittingent Beliped
Local time
Today, 04:24
Joined
Nov 3, 2010
Messages
6,142
Google gives 91,700,000 hits on "does not work". Which one applies?
 

vbaInet

AWF VIP
Local time
Today, 03:24
Joined
Jan 22, 2010
Messages
26,374
Yes, please be more concise next time.

I've uploaded a simple example.
 

Attachments

  • PythonArgs.zip
    11.5 KB · Views: 657

Users who are viewing this thread

Top Bottom