title: VBA that runs shell command works only in debug mode
body: <p>I wrote some VBA code that calls <code>ftp.exe</code> via shell command.  When the code runs, the shell command does not execute.  However, if I step through the code in debug mode, it works every time.  Here is the code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub FTPFile(sSrc As String)
      Dim sHost As String
      Dim sUser As String
      Dim sPass As String
      Dim sDest As String
      Dim sFTPCmds As String
      Dim strConnect As String
  
      'Build up the necessary parameters
      sHost = "&lt;redacted&gt;"
      sUser = "&lt;redacted&gt;"
      sPass = "&lt;redacted&gt;"
      sDest = "\"
  
      'Write the FTP commands to a text file
      iFNum = FreeFile
      sFTPCmds = "&lt;path redacted&gt;" &amp; "FTPCmd.tmp"
      Open sFTPCmds For Output As #iFNum
          Print #iFNum, "op " &amp; sHost
          Print #iFNum, "user " &amp; sUser &amp; " " &amp; sPass
          Print #iFNum, "cd " &amp; sDest
          Print #iFNum, "put " &amp; sSrc
          Print #iFNum, "bye"
      Close #iFNum
  
      Shell Environ("WINDIR") &amp; "\System32\ftp.exe -n -s:" &amp; sFTPCmds
  End Sub
  </code></pre>
  
  <p>The only possible idea I came up with is that the user permissions that call this command differ based on whether the call occurs in debug mode or running, but I am unsure how to change the command.</p>