title: Loop though files in a Folder on Mac OS X - VBA Excel 2011
body: <p>I am trying to loop through files in a folder on Mac OS X using VBA Excel 2011. I tried the following code, but it does not work.</p>
  
  <pre><code>Sub ListAllFilesInDir()
      Dim strFile As String
      Dim strPath1 As String
  
      strPath1 = ActiveWorkbook.FullName
      MsgBox strPath1
      strFile = Dir(strPath1)
      MsgBox strFile
      strFile = Dir()
      MsgBox strFile
      strFile = Dir()
      MsgBox strFile
  End Sub
  </code></pre>
  
  <p>I get the name of the active workbook when the program reaches the first <code>MsgBox strFile</code>. I read somewhere that using <code>Dir</code> without an argument results in the next file in the folder. But that does not work for me. I get an empty message box for the second <code>MsgBox strFile</code> command and an error (Runtime error 5: Invalid Procedure call or argument" for the third <code>MsgBox strFile</code> command. I have 4 files in the folder that I am trying to loop through.</p>
  
  <p>Also, what would I do to list only ".xslx" files</p>