|
楼主 |
发表于 2024-2-1 10:03
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub ykcbf()
Dim cnn As Object
Dim SQL$, MyPath$, MyFile$, a, arr(), i%, ii%, t$, m%
t = [c1]
Application.ScreenUpdating = False
ActiveSheet.UsedRange.Offset(3).ClearContents
MyPath = ThisWorkbook.Path & "\"
MyFile = Dir(MyPath & "*.xls")
Do While MyFile <> ""
If MyFile <> ThisWorkbook.Name Then
m = m + 1
ReDim Preserve arr(1 To m)
arr(m) = MyFile
End If
MyFile = Dir()
Loop
Set cnn = CreateObject("adodb.connection")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & MyPath & arr(1)
For i = 1 To m Step 16
SQL = ""
For ii = i To i + 15
If ii > m Then Exit For
If Len(SQL) Then SQL = SQL & " union all "
SQL = SQL & "select 科目编码,辅助核算,'" & Replace(arr(ii), ".xls", "") & "','" & "新的工作表$a3:f3000" & "' from [Excel 8.0;Database=" & MyPath & arr(ii) & "]." & "新的工作表$a3:f3000" & " where 科目编码='" & t & "'"
Next
[a65536].End(xlUp).Offset(1).CopyFromRecordset cnn.Execute(SQL)
Next
cnn.Close
Set cnn = Nothing
Application.ScreenUpdating = True
MsgBox Timer - tt
End Sub
我找了一个多工作簿多表的改了改运行不了,老师们能帮我看看么 |
|