title: return csv file as recordset
body: <p>I have an external program that exports data into CSV files. My users would like to have access to this data through a VBA function in excel. In order to do this, I thought about wrapping the CSV file read into a function that returns a ADODB.Recordset. My code is</p>
  
  <pre><code>Public Function getData(fileName As String) As ADODB.Recordset
  Dim path As String
  path = "C:\testDir\"
  Dim cN As New ADODB.Connection
  Dim RS As New ADODB.Recordset
  cN.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" &amp; _
                 "Data Source=" &amp; path &amp; ";" &amp; _
                 "Extended Properties=""text; HDR=Yes; FMT=Delimited; IMEX=1;""")
  RS.ActiveConnection = cN
  RS.Source = "select * from " &amp; fileName
  Set getData = RS
  End Function
  </code></pre>
  
  <p>I am trying to call this function using</p>
  
  <pre><code>Dim a As ADODB.Recordset
  Set a = getData("testFile.csv")
  a.Open()
  </code></pre>
  
  <p>At this point, I get a compile error saying '=' expected. Could someone point me in the right direction on how I should call my function and loop through the data? </p>