|
楼主 |
发表于 2011-10-23 16:30
|
显示全部楼层
zhaogang1960 发表于 2011-10-23 15:29
请测试
Sub 如何合并多个csv文件为一个文件()
Dim cnn As Object, SQL$, MyPath$, MyFile$, m&
Dim cnn As Object, SQL$, MyPath$, MyFile$, m&
Set cnn = CreateObject("adodb.connection") MyPath = ThisWorkbook.Path & "\"
If Dir(MyPath & "total.csv") <> "" Then Kill MyPath & "total.csv"
MyFile = Dir(MyPath & "*.csv")
Do While MyFile <> ""
m = m + 1
If SQL = "" Then SQL = "select * from " & MyFile Else SQL = SQL & " union all select * from " & MyFile MyFile = Dir()
Loop
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='text;FMT=DELIMITED';Data Source=" & MyPath SQL = "select * into [total.csv] from (" & SQL & ")"
cnn.Execute SQL
MsgBox m & "个csv文件已成功合并为total.csv!"
cnn.Close
Set cnn = Nothing
Kill MyPath & "schema.ini"
版主,你能不能帮我解读下红色字体部分,我不明白意思啊? |
|