Sub Macro3()
Application.ScreenUpdating = False
Set oConn = CreateObject("ADODB.CONNECTION")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & ";Extended Properties=""text;HDR=Yes;FMT=Delimited"""
Set oRS = CreateObject("ADODB.RECORDSET")
'Now actually open the text file and import into Excel
oRS.Open "SELECT * FROM 201403_OSA_BY_SKU_DT.csv", oConn, 3, 1, 1
While Not oRS.EOF
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Range("A1").CopyFromRecordset oRS, 1000000
Wend
Application.ScreenUpdating = True
End Sub
Application.ScreenUpdating = False
Set oConn = CreateObject("ADODB.CONNECTION")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & ";Extended Properties=""text;HDR=Yes;FMT=Delimited"""
Set oRS = CreateObject("ADODB.RECORDSET")
'Now actually open the text file and import into Excel
oRS.Open "SELECT * FROM 201403_OSA_BY_SKU_DT.csv", oConn, 3, 1, 1
While Not oRS.EOF
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Range("A1").CopyFromRecordset oRS, 1000000
Wend
Application.ScreenUpdating = True
End Sub
本文介绍了一个使用VBA宏从CSV文件中读取数据,并将其导入到新的Excel工作表中的方法。通过创建ADODB连接对象和记录集对象,实现对CSV文件的数据访问,然后循环将数据复制到多个工作表中。

被折叠的 条评论
为什么被折叠?



