title: Is file path needed in (Shell Function) VBA?
body: <p>I have a Matlab-generated executable file, <em>Myfile.exe</em> to call from <a href="/questions/tagged/excel-vba" class="post-tag" title="show questions tagged &#39;excel-vba&#39;" rel="tag">excel-vba</a>. I learned (Shell Function) is what I need to use.</p>
  
  <p>I don't want to include the whole file path as I do not want to restrict the user to a certain folder in a certain location on each computer.  </p>
  
  <p>I have the following code to call the executable, which works fine:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub MyExe()
      On Error Resume Next
      Shell ("C:\Users\elwany\Desktop\Myfolder\Myfile.exe")
      If Err &lt;&gt; 0 Then
          MsgBox "Can't start the application.", vbCritical, "Error"
      End If
  End Sub
  </code></pre>
  
  <p><strong>My problem/question is</strong>
  I put the executable + the Excel file with the VBA project in the same folder (Myfolder), and then I modify the code to:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub MyExe()
      On Error Resume Next
      Shell ("Myfile.exe")
      If Err &lt;&gt; 0 Then
          MsgBox "Can't start the application.", vbCritical, "Error"
      End If
  End Sub
  </code></pre>
  
  <p>Sometimes it works, sometimes it doesn't!  </p>
  
  <p>For example, yesterday I ran the VBA code, it worked.  Today I opened the same Excel file, same folder, same everything, it gives "Can't Start Application" error msg!!</p>
  
  <ol>
  <li>Is it not okay to remove the file path even if I have everything in one folder?</li>
  <li>Why does it sometimes work, sometimes not?</li>
  <li>Is adding the file path absolutely mandatory?</li>
  </ol>