title: Is it possible to batch convert csv to xls using a macro?
body: <p>I have a large amount of <code>csv</code> files that I need in <code>.xls</code> format. Is it possible to run a batch conversion with a macro or best done with another language?</p>
  
  <p>I have used this code <a href="http://www.ozgrid.com/forum/showthread.php?t=71409&amp;p=369573#post369573" rel="nofollow">http://www.ozgrid.com/forum/showthread.php?t=71409&amp;p=369573#post369573</a> to reference my directory but I'm not sure of the command to open each file and save them. Here's what I have:</p>
  
  <pre><code>Sub batchconvertcsvxls()
      Dim wb As Workbook
      Dim CSVCount As Integer
      Dim myVar As String
  
      myVar = FileList("C:\Documents and Settings\alistairw\My Documents\csvxlstest")
      For i = LBound(myVar) To UBound(myVar)
  
          With wb
  
              Application.Workbooks.OpenText 'How do I reference the myvar string ?
              wb.SaveAs '....
  
          End With
  
      Next
  End Sub
  
  Function FileList(fldr As String, Optional fltr As String = "*.*") As Variant
      Dim sTemp As String, sHldr As String
      If Right$(fldr, 1) &lt;&gt; "\" Then fldr = fldr &amp; "\"
      sTemp = Dir(fldr &amp; fltr)
      If sTemp = "" Then
          FileList = Split("No files found", "|") 'ensures an array is returned
          Exit Function
      End If
      Do
          sHldr = Dir
          If sHldr = "" Then Exit Do
          sTemp = sTemp &amp; "|" &amp; sHldr
      Loop
      FileList = Split(sTemp, "|")
  End Function
  </code></pre>
  
  <p><strong>Edit: The files are .txt files formatted as csv</strong></p>