|
- Sub test1() '是否完成 不知怎么填……
-
- Dim results(), ar, br(1), cel As Range, vrt
- Dim i As Long, j As Long, cnt As Long
- Dim Conn As Object, re As Object, dict As Object, vKey
- Dim strConn As String, SQL As String, s As String, p As String, f As String
-
- Set Conn = CreateObject("ADODB.Connection")
- Set dict = CreateObject("Scripting.Dictionary")
- Set re = CreateObject("VBScript.RegExp")
- re.Global = True
- re.Pattern = "(\D+)(\d+)(\D+)(\d+)"
-
- ar = Split("B3 D3 D2 F3")
- For Each vrt In ar
- For Each cel In Range(vrt)
- s = cel.Address(, , xlR1C1)
- For j = 4 To 2 Step -2
- br(-CInt(j = 2)) = re.Replace(s, "$" & j) - 1
- Next
- dict.Add Join(br, "|"), dict.Count + 1
- Next
- Next
- ReDim results(1 To 2345, 1 To dict.Count + 1)
- Set re = Nothing
-
- ActiveSheet.UsedRange.Offset(2).ClearContents
- Application.ScreenUpdating = False
-
- s = "Excel 12.0;HDR=NO;IMEX=1;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=NO';Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=NO';Data Source="
- End If
- 'Conn.Open strConn & ThisWorkbook.FullName
-
- p = ThisWorkbook.Path & "\"
- SQL = "SELECT * FROM [" & s & p & "[.f]].[$A1:F3]"
- f = Dir(p & "*.xls*")
- Do
- If f <> ThisWorkbook.Name Then
- cnt = cnt + 1
- If cnt = 1 Then Conn.Open strConn & p & f
- ar = Conn.Execute(Replace(SQL, "[.f]", f)).GetRows
- For Each vKey In dict.Keys
- vrt = Split(vKey, "|")
- results(cnt, dict(vKey)) = ar(vrt(0), vrt(1))
- Next
- results(cnt, UBound(results, 2)) = "是否 怎么填?"
- End If
- f = Dir
- Loop While f <> ""
-
- Range("A3").Resize(cnt, UBound(results, 2)) = results
-
- Conn.Close
- Set Conn = Nothing
- Set dict = Nothing
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|