|
本帖最后由 zhaogang1960 于 2014-6-30 19:37 编辑
张雄友 发表于 2014-6-30 19:30
如果有标题怎么办?只要A1单元格一个标题就好了。
Sub ADO加数组法()
Dim Fso As Object, File As Object, cnn As Object, SQL$
Dim arr, brr(1 To 65535, 1 To 1), f As Boolean, i&, m&, n&
Application.ScreenUpdating = False
Application.StatusBar = " 正在导入数据,请等待……"
Cells.ClearContents
Set Fso = CreateObject("Scripting.FileSystemObject")
For Each File In Fso.GetFolder(ThisWorkbook.Path).Files
If File.Name Like "*.xls" Then
If File.Name <> ThisWorkbook.Name Then
If Not f Then
Set cnn = CreateObject("adodb.connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;hdr=yes';Data Source=" & File
SQL = "select 车间 from [Sheet1$o:o] where 车间 is not null"
f = True
Else
SQL = "select 车间 from [Excel 8.0;hdr=yes;Database=" & File & ";].[Sheet1$o:o] where 车间 is not null"
End If
arr = cnn.Execute(SQL).GetRows
For i = 0 To UBound(arr, 2)
m = m + 1
If m > 65535 Then
Cells(1, n + 1) = "车间"
Cells(2, n + 1).Resize(65535) = brr
m = 1
n = n + 1
Erase brr
End If
brr(m, 1) = arr(0, i)
Next
End If
End If
Next
Cells(1, n + 1) = "车间"
Cells(2, n + 1).Resize(m) = brr
Set File = Nothing
Set Fso = Nothing
cnn.Close
Set cnn = Nothing
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|