title: VBA to open Excel Workbook if file exists, and open a different if it does not
body: <p>I have spent my whole morning on this and cannot get it working properly.  A simple Excel userform was created asking for a filename.  If the file exists in the directory I want it to open.  If it does not exist I want a &quot;template&quot; file opened instead.  I have the does not exist working properly, however cannot get the &quot;does exist&quot; part working. Please help.</p>
  <pre><code>Private Sub CmdEnter_Click()
  Dim Path As String
  Dim File As String
   
  Path = Range(&quot;Search!B1&quot;)
  File = TxtOrder.Value
      
  'If File exists then open.
  If Dir(Path &amp; File &amp; &quot;.xlsm&quot;) = Path &amp; File &amp; &quot;.xlsm&quot; Then
      Workbooks.Open FileName:=Path &amp; File &amp; &quot;.xlsm&quot;
      
  'If File does not exist then open.
  ElseIf Dir(Path &amp; File &amp; &quot;.xlsm&quot;) = Error Then
      Workbooks.Open FileName:=Path &amp; &quot;QCSFormTrial.xlsm&quot;
      
  End If
  
  'Close Dialog and Close Workbook
  Workbooks(&quot;QCSLaunch.XLSM&quot;).Close SaveChanges:=False
  </code></pre>
  <p>End Sub</p>