|
Sub limont()
Dim Cn As Object, StrSQL$, Path$, FileName$
Set Cn = CreateObject("Adodb.Connection")
Path = ThisWorkbook.Path & "\"
FileName = Dir(Path & "*.xls?")
Do While FileName <> ""
If FileName <> "源数据.xlsm" Then
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;Hdr=No';Data Source=" & Path & FileName
StrSQL = "Update [Sheet1$] Set F1=Null,F2=Null Where F2 In(Select * From [Excel 12.0;Hdr=No;DataBase=" & ThisWorkbook.FullName & "].[Sheet1$B:B])"
Cn.Execute (StrSQL)
StrSQL = "Select '" & Split(FileName, ".xlsx")(0) & "',Count(*) From [Sheet1$] Where F1<>''"
Range("D" & Range("D" & Rows.Count).End(xlUp).Row + 1).CopyFromRecordset Cn.Execute(StrSQL)
Cn.Close
End If
FileName = Dir
Loop
End Sub |
|