title: Open .csv file with Excel VBA
body: <p>I'm having a problem with this piece of my code in VBA and I can't figure out why it isn't working! I've tried another code to see if it was the loop that has the issue but the issue is specifically opening the files and not iterating through them.</p>
  <pre><code>Sub fileloop(Path)
  Dim strFile As String, strPath As String
  Dim MyBook As Workbook
  
  strPath = Path '&amp; &quot;\*.csv&quot;
  strFile = Dir(strPath &amp; &quot;\*.csv&quot;)
  
  MsgBox (strFile)
  
  While strFile &lt;&gt; &quot;&quot;
  
  'placed another messagebox here to see if the strFile was the same inside the loop.
  MsgBox (strFile)
  
  'this line has the error.   
      Workbooks.OpenText FileName:=strFile, _
  DataType:=xlDelimited, Comma:=True, Local:=True
  
    set MyBook = ActiveWorkbook
  
      Call SortColumnB(MyBook)
  
      strFile = Dir
  
   Wend
  
  End Sub
  </code></pre>
  <p>The error message I get goes something like this:</p>
  <blockquote>
  <p>'AC000W0009.csv' could not be found. Check the spelling of the file name, and verify that the file location is correct.</p>
  <p>If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted.</p>
  </blockquote>
  <p>I've tried so many variations apart from the one listed above and I can't understand why VBA won't recognize that the file exists.</p>
  <p><strong>EDIT</strong></p>
  <p>Going off of what Mike said about opening a file with the complete path the changes I made to the code to let it open .csv files:</p>
  <pre><code> strPath = Path &amp; &quot;\&quot;
  strFile = Dir(strPath &amp; &quot;*.csv&quot;)
  
  
  
  While strFile &lt;&gt; &quot;&quot;
  MsgBox (strFile)                 'added path to file name.
      Workbooks.OpenText FileName:=strPath &amp; strFile, _
  DataType:=xlDelimited, Comma:=True, Local:=True
  </code></pre>