|
- Sub Contents()
- '*******************by大独裁家*******************
- Application.ScreenUpdating = False
- Dim i, j, k, arr, brr, crr, x, y
- ' Dim conn As New ADODB.Connection '连接对象
- ' Dim rst As New ADODB.Recordset '记录集
- Dim conn As Object, rst As Object
- Set conn = CreateObject("ADODB.Connection")
- Set rst = CreateObject("ADODB.Recordset")
- Dim mypath, sql
- mypath = ThisWorkbook.FullName
- conn.Open "provider=Microsoft.ACE.OLEDB.12.0; extended properties=excel 12.0; data source=" & mypath
- sql = "SELECT 馆编档号, 卷内文件份数 from [案卷目录$]"
- rst.Open sql, conn, 3, 2 '执行sql语句,获得记录集
- arr = rst.GetRows '得到一个结果数组,行列转置,下标为0
- Sheets("卷内目录").Cells(2, "C").Resize(1048575).ClearContents
- Sheets("卷内目录").Cells(2, "H").Resize(1048575).ClearContents
- k = 2
- For i = 0 To UBound(arr, 2)
- If arr(1, i) <> "" Then
- Sheets("卷内目录").Cells(k, "C").Resize(arr(1, i)) = arr(0, i)
- k = k + arr(1, i)
- End If
- Next
- brr = Sheets("卷内目录").Cells(1, 1).CurrentRegion
- For i = 2 To UBound(brr)
- ' If i = 67 Then Stop
- If brr(i, 16) Like "*-*" Then
- crr = Split(brr(i, 16), "-")
- brr(i, 8) = crr(1) - crr(0)
- ElseIf brr(i + 1, 16) Like "*-*" Then
- crr = Split(brr(i + 1, 16), "-")
- brr(i, 8) = crr(0) - brr(i, 16)
- Else
- brr(i, 8) = brr(i + 1, 16) - brr(i, 16)
- End If
- If brr(i, 8) = 0 Then brr(i, 8) = 1
- Next
- ReDim crr(2 To UBound(brr), 1 To 1)
- For i = 2 To UBound(brr)
- crr(i, 1) = brr(i, 8)
- Next
- Sheets("卷内目录").Cells(2, "H").Resize(UBound(crr) - 1) = crr
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|