|
- Sub test1() '。
- Dim Conn As Object, Dict As Object, Cel As Range, strConn As String
- Dim p As String, f As String, s As String, SQL As String
-
- Application.ScreenUpdating = False
- Set Cel = Sheet3.Range("A2")
- Cel.Resize(12345, 6).ClearContents
-
- Set Dict = CreateObject("Scripting.Dictionary")
- Set Conn = CreateObject("ADODB.Connection")
- s = "Excel 12.0;HDR=yes;Database="
- If Application.Version < 12 Then
- s = Replace(s, "12.0", "8.0")
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=yes';Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=yes';Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.FullName
- p = ThisWorkbook.Path & "\学期终版备份\"
- f = Dir(p & "*.xls?")
- SQL = "SELECT 姓名,学号,报名年级,报名时间,实际缴纳,'[f]' AS 工作簿 FROM [" & s & p & "[f]].[人财报表$B1:AF] WHERE 姓名='" & Sheet1.Range("E3").Value & "'"
- Do
- If f <> ThisWorkbook.Name Then
- Dict.Add Replace(SQL, "[f]", f), vbNullString
- If Dict.Count = 49 Then
- Cel.CopyFromRecordset Conn.Execute(Join(Dict.Keys, " UNION ALL "))
- Dict.RemoveAll
- Set Cel = Cel.End(xlDown).Offset(1)
- End If
- End If
- f = Dir
- Loop While Len(f)
- If Dict.Count Then Cel.CopyFromRecordset Conn.Execute(Join(Dict.Keys, " UNION ALL "))
-
- Conn.Close
- Set Conn = Nothing
- Set Cel = Nothing
- Set Dict = Nothing
-
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|