|
- Sub test0() '适用于较高版本excel
- Dim Fso As Object, oFile As Object, Conn As Object
- Dim SQL As String, strPath As String, strFile As String
-
- Application.ScreenUpdating = False
-
- strPath = ThisWorkbook.Path
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set Conn = CreateObject("ADODB.Connection")
- Conn.Open "provider=Microsoft.ACE.OLEDB.12.0;Extended Properties =Excel 12.0;Data Source=" & ThisWorkbook.FullName
-
- For Each oFile In Fso.GetFolder(strPath).Files
- If oFile.Name Like "*.csv" Then
- strFile = Replace(oFile.Path, ".csv", ".xlsx")
- If Fso.FileExists(strFile) Then Fso.DeleteFile strFile
- SQL = "SELECT * INTO [Excel 12.0 XML;Database=" & strFile & "].[" & Replace(oFile.Name, ".csv", "") & "] " & _
- "FROM [Text;FMT=CSVDelimited;HDR=YES;Database=" & strPath & "].[" & oFile.Name & "]"
- Conn.Execute SQL
- End If
- Next
-
- Set oFile = Nothing
- Set Fso = Nothing
- Conn.Close
- Set Conn = Nothing
-
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|