title: Running Python script from VBA, checking to see if 'RetVal = Shell' command is working
body: <p><strong>Original Question</strong></p>
  
  <p>When I go into C:\Users\HP\Documents\Python Scripts and click EbayWebScraper.py the script runs. It takes about 30 seconds but the output is correct.</p>
  
  <p>I want to run this script from within Excel / VBA. I tried using the code 'RetVal = Shell' and writing it in 6 different ways. After the 6 failed attempts, I turned the code into comments. </p>
  
  <pre><code>Sub Python()
  
  'RetVal = Shell("python.exe C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py", vbNormalFocus)
  
  
  'RetVal = Shell("C:\Users\HP\AppData\Local\Programs\Python\Python37-32\python.exe " &amp; "C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py")
  
  'RetVal = Shell("C:\Users\HP\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py")
  
  'RetVal = Shell("C:\Users\HP\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py", vbNormalFocus)
  
  
  'RetVal = Shell("python.exe" &amp; "C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py", vbNormalFocus)
  
  'RetVal = Shell("python.exe" &amp; "C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py")
  
  
  End Sub
  </code></pre>
  
  <p>Do I need to slow the VBA macro down somehow? Is it a case of the VBA macro working too quickly and not giving the Python script enough time? </p>
  
  <p>I read this <a href="https://stackoverflow.com/questions/46117587/vba-macro-running-too-fast">VBA Macro running too fast</a> and experimented with </p>
  
  <pre><code>Application Wait (Now + TimeValue (0:00:10")).
  </code></pre>
  
  <p>Unfortunately the experiment did not seem to work.</p>
  
  <p>I use Loom to record the screen and then I play back the recording and have a better look at any error messages that appear in CMD. Unfortunately to the best of my knowledge every error message I have occurred, I have now fixed. </p>
  
  <p><strong>Update 1</strong></p>
  
  <p>I don't know if I am being really stupid. To the best of my knowledge I have provided the right file directory. The link 'Windows Explorer File Directory' is for a screenshot I took.</p>
  
  <pre><code>Microsoft Windows [Version 10.0.17134.165]
  (c) 2018 Microsoft Corporation. All rights reserved.
  
  C:\Users\HP&gt;python C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py
  python: can't open file 'C:\Users\HP\Documents\Python': [Errno 2] No such file or directory
  &gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Cs6Wc.png" rel="nofollow noreferrer">Windows Explorer File Directory</a></p>
  
  <p><strong>Update 2</strong></p>
  
  <p>This also failed. </p>
  
  <pre><code>Microsoft Windows [Version 10.0.17134.165]
  (c) 2018 Microsoft Corporation. All rights reserved.
  
  C:\Users\HP&gt;Documents\Python Scripts\EbayWebScraper.py
  'Documents\Python' is not recognized as an internal or external command,
  operable program or batch file.
  </code></pre>
  
  <p><strong>Update 3</strong></p>
  
  <p>When I ran this code (which I got from <a href="https://stackoverflow.com/questions/8902022/wait-for-shell-to-finish-then-format-cells-synchronously-execute-a-command">Wait for Shell to finish, then format cells - synchronously execute a command</a>) - </p>
  
  <pre><code>Sub Python2()
  
  Dim wsh As Object
  Set wsh = VBA.CreateObject("WScript.Shell")
  Dim waitOnReturn As Boolean: waitOnReturn = True
  Dim windowStyle As Integer: windowStyle = 1
  Dim errorCode As Long
  
  errorCode = wsh.Run("C:\Users\HP\Documents\Python Scripts\EbayWebScraper.py", windowStyle, waitOnReturn)
  
  If errorCode = 0 Then
      MsgBox "Done! No error to report."
  Else
      MsgBox "Program exited with error code " &amp; errorCode &amp; "."
  End If
  
  End Sub
  </code></pre>
  
  <p>I got the error -</p>
  
  <p>Run-time error '-2147024894 (80070002)':
  Method 'Run' of object 'IWshShell3' failed</p>
  
  <p><strong>Update 4</strong></p>
  
  <p>I am looking at <a href="https://stackoverflow.com/questions/21267283/error-running-shell-object-commands-through-excel-vba">Error running Shell object / commands through Excel VBA</a>.</p>
  
  <p><strong>Update 5</strong></p>
  
  <p>This code finally worked (I got the code from the link in Update 4).</p>
  
  <pre><code>    Sub Python3()
  
  Dim wsh As Object
  Set wsh = VBA.CreateObject("WScript.Shell")
  Dim waitOnReturn As Boolean: waitOnReturn = True
  Dim windowStyle As Integer: windowStyle = 1
  Dim errorCode As Long
  
  errorCode = wsh.Run(Chr(34) &amp; "C:\Users\HP\Documents\Python Scripts" &amp; "\EbayWebScraper.py" &amp; Chr(34))
  
  If errorCode = 0 Then
      MsgBox "Done! No error to report."
  Else
      MsgBox "Program exited with error code " &amp; errorCode &amp; "."
  End If
  
  End Sub
  </code></pre>