|
Sub Limonet()
Dim Cn As Object, Path$, FileName$, StrSQL$, Rst As Object
Set Cn = CreateObject("ADODB.Connection")
Set Rst = CreateObject("adodb.recordset")
Path = ThisWorkbook.Path & "\数据库\"
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
FileName = Dir(Path & "*.xlsx")
Do While FileName <> ""
StrSQL = StrSQL & " Union All Select 修改时间,文件名称,文件路径 From [Excel 12.0;DataBase=" & Path & FileName & "].[第0部分$A2:F] Where 文件名称 Like '%" & Sheet1.Range("B1") & "%'"
FileName = Dir
Loop
Rst.Open Mid(StrSQL, 12), Cn, 1, 3
If Rst.RecordCount Then
Sheet3.Copy after:=Sheet1
ActiveSheet.Name = Sheet1.Range("B1")
Range("A2").CopyFromRecordset Rst
Columns("A:C").AutoFit
End If
End Sub |
|