|
- Sub test1()
- Dim Conn As Object, strConn As String
- Dim p As String, f As String, s As String, c As Integer
-
- ActiveSheet.UsedRange.ClearContents
- Application.ScreenUpdating = False
-
- s = "Excel 12.0;HDR=yes;Database="
- If Application.Version < 12 Then
- s = Replace(s, "12.0", "8.0")
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
-
- Set Conn = CreateObject("ADODB.Connection")
- Conn.Open strConn & ThisWorkbook.FullName
-
- p = "D:\桌面\合并\1\"
- f = Dir(p & "*.xls?")
-
- While Len(f)
- If p & f <> ThisWorkbook.FullName Then
- c = c + 1
- Cells(1, c) = Split(f, ".xls")(0)
- Cells(2, c).CopyFromRecordset Conn.Execute("SELECT * FROM [" & s & p & f & "].[$I1:I]")
- End If
- f = Dir
- Wend
-
- Conn.Close
- Set Conn = Nothing
-
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|