Public Function getData(fileName As String) As ADODB.Recordset
Dim path As String
path = "C:\ExcelOMG Cookbook 2016\Closed CSV\"
Dim cN As ADODB.Connection
Dim RS As ADODB.Recordset
Set cN = New ADODB.Connection
Set RS = New ADODB.Recordset
' cN.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "Data Source=" & path & ";" & _
' "Extended Properties=""text; HDR=Yes; FMT=Delimited; IMEX=1;""")
cN.Open ("Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & path & ";" & _
"Extended Properties=""text; HDR=Yes; FMT=Delimited; IMEX=1;""")
RS.ActiveConnection = cN
RS.Source = "select * from " & fileName
Set getData = RS
End Function
Sub GetDataFromCSV()
Dim a As ADODB.Recordset
Set a = getData("DataFile.csv")
a.Open
Range("A1").CopyFromRecordset a
a.Close
End Sub
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.