0

I'm trying to execute a python code with command line argument using VBA. My python file name is test.py. While I'm executing following command using command prompt

python test.py Sales

Then my python code process sales data & store the processed output in a table in SQL server.I can able to see the uploaded data in SQL server. I would like to execute this python script using VBA. So I wrote following code

Sub executePython1()
 Dim wsh As Object
 Set wsh = CreateObject("WScript.Shell")
 arg = "Sales"
 Dim shell_exec As Object
 Set shell_exec = wsh.Exec("""python.exe""" & 
 """C:\x1\test.py """ & arg)
 MsgBox "Executed"
End Sub

After running the code I'm seeing "Executed" message but I'm unable to see any data in my SQL Server table. Can you help me to resolve this issue?

I'm working on Windows azure & running python 3.7

Sonia
  • 464
  • 10
  • 21
  • Have a look here: https://stackoverflow.com/questions/15951837/wait-for-shell-command-to-complete. – Sam Mar 27 '19 at 08:19
  • @Sam, I have seen that stack overflow post & tried also.But that was also not working – Sonia Mar 27 '19 at 10:35
  • The first thing to find out is if it runs synchronously or asynchronously. If you are running it asynchronously, then your msgbox will come directly, regardless of the result. – Sam Mar 27 '19 at 13:32
  • @Sam I don't think this is happening due to asynchronous run as I ran the python script first using command prompt & the time taken to get the message box using VBA is slightly more than the time taken to run the code using python in command prompt. My guess is there is some issue in my VBA code. – Sonia Mar 29 '19 at 05:32
  • Wild guesses coming... Do you have more than one python installation in your system? If so, use a fully qualified path to the one you want to use. – Sam Mar 29 '19 at 12:11
  • No I have only python 3.7 in my system – Sonia Apr 01 '19 at 09:45
  • Then I suggest that you try various combinations of `cmd /c *something something*` and/or putting the call in a bat file. – Sam Apr 01 '19 at 11:10

0 Answers0