title: VBA Error While Opening Excel Worksheet in a Loop
body: <p>I am trying to perform few procedure on few excel sheets and using the following code. I am getting a RunTime Error 1004 for <strong>Application.Workbooks.Open (StrFile)</strong>. It seems like it is not able to find the file. The reason why I think that is because it is not showing the filepath but just the file in the directory shown below in the screenshot:</p>
  
  <p><img src="https://i.stack.imgur.com/frPkp.jpg" alt="image of where error occurs"></p>
  
  <pre><code>Sub ExcelerFinal()
  
  Dim FileCount As Integer
  Dim FileName As String, FileNameGIS As String
  Dim FilePath As String, StrFile As String
  
  FileCount = 0
  FileName = "MyFile_" + CStr(FileCount)
  FileNameGIS = "MyFileGIS_" + CStr(FileCount)
  
  FilePath = "E:\Database Project\ACS Estimate 2011\LoopTest\Test_RawData\"
  
  StrFile = Dir(FilePath &amp; "*.xlsx")
  
  While StrFile &lt;&gt; ""
      Application.Workbooks.Open (StrFile) 'Error occurs on this line 
      FileCount = FileCount + 1
      FileName = "MyFile_" + CStr(FileCount)
      FileNameGIS = "MyFileGIS_" + CStr(FileCount)
  
      ' Lots of code to manipulate file
      ' unrelated to issue
      Windows(FileNameGIS).Close
      StrFile = Dir
  Wend
  End Sub
  </code></pre>