|
Sub 可用于WPS() '已测试,可用于WPS,一定要安装 AccessDatabaseEngine
Dim Cnn As Object, strCnn As String, SQL As String, p As String, f As String, s As String
ActiveSheet.UsedRange.Offset(2).ClearContents
Application.ScreenUpdating = False
Set Cnn = CreateObject("ADODB.Connection")
strCnn = "Provider=Microsoft.jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=no';Data Source ="
SQL = "SELECT f1,f2,f5,'[s]' FROM [$C4:G] WHERE f1 LIKE '%" & Range("B1").Value & "%'"
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.xls?")
While Len(f)
If f <> ThisWorkbook.Name Then
Cnn.Open strCnn & p & f
s = Split(f, ".")(0)
Cells(Rows.Count, 1).End(xlUp).Offset(1).CopyFromRecordset Cnn.Execute(Replace(SQL, "[s]", Split(f, ".")(0)))
Cnn.Close
End If
f = Dir
Wend
Set Cnn = Nothing
Application.ScreenUpdating = True
Beep
End Sub |
|