|
SQL方法的汇总查询
完整代码见附件
- '*********************************
- '******* 北极狐工作室出品 ******
- '******* QQ:14885553 ******
- '*********************************
- Sub Opiona2() '//这个速度快,是因为不用打开Excel
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- t = Timer '//开始时间
- Set SH0 = Worksheets("Sheet2")
- SH0.Range("B29:R65536").ClearContents
-
- FileArr = FileAllArr(ThisWorkbook.Path, "档案M.xls", ThisWorkbook.Name, False)
- For I = 0 To UBound(FileArr)
- Str_coon = "Provider=Microsoft.JET.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=NO;imex=1';Data Source=" & FileArr(I) '//OFFICE2003
- StrSQL = "SELECT * FROM [Sheet1$H1:AJ7]"
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, False)
-
- SH0.Cells(I + 29, 2) = SQLARR(3, 28)
- If InStr(SQLARR(0, 0), "√") > 0 Then SH0.Cells(I + 29, 4) = "男"
- If InStr(SQLARR(0, 2), "√") > 0 Then SH0.Cells(I + 29, 4) = "女"
- SH0.Cells(I + 29, 5) = SQLARR(4, 28) & "岁"
- SH0.Cells(I + 29, 6) = SQLARR(5, 28)
- SH0.Cells(I + 29, 8) = SQLARR(6, 28)
- SH0.Cells(I + 29, 12) = Format(Now, "YYYY-MM-DD")
-
- StrSQL = "SELECT * FROM [Sheet5$H9:H9]"
- SQLARR = GET_SQL_To_Arr(StrSQL, Str_coon, False)
- SH0.Cells(I + 29, 15) = SQLARR(0, 0)
- Next
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
|