|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
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 |
|