|
带密码,ADO不能直接连接,自己找个代码去除密码吧。
Sub a()
Dim MuLu As String
Dim myfile As String, ms As String
Dim brr, D, x
Dim i As Integer
Dim cnn As Object, rs As Object, SQL$, CRR, Arr(1 To 60000, 1 To 9), M As Integer
MuLu = ThisWorkbook.Path
Set D = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
If Left(MuLu, 1) <> "\" Then MuLu = MuLu & "\"
D.Add MuLu, ""
i = 0
Do While i < D.Count
brr = D.KEYS
myfile = Dir(brr(i), vbDirectory)
Do While myfile <> ""
If myfile <> "." And myfile <> ".." Then
If (GetAttr(brr(i) & myfile) And vbDirectory) = vbDirectory Then D.Add (brr(i) & myfile & "\"), ""
End If
myfile = Dir
Loop
i = i + 1
Loop
For Each x In D.KEYS
myfile = Dir(x & "*.xls")
Do While myfile <> "" And myfile <> ThisWorkbook.Name
ms = ms & x & myfile
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.Jet.OleDb.4.0;Extended Properties='Excel 8.0;HDR=NO'; Data Source=" & ms
SQL = "select f2,f3,f4,f6,f7,f9 from [汇总表$a4:k] where f2 is not null"
Set rs = cnn.Execute(SQL)
CRR = rs.getRows
For i = 0 To UBound(CRR, 2)
M = M + 1
Arr(M, 1) = Left(myfile, InStr(myfile, "公司") + 1)
Arr(M, 2) = Replace(Left(myfile, InStr(myfile, "月")), Arr(M, 1), "")
Arr(M, 3) = Replace(Mid(x, InStrRev(Left(x, Len(x) - 1), "\") + 1), "\", "") ' 返回文件夹名称
Arr(M, 4) = CRR(0, i)
Arr(M, 5) = CRR(1, i)
Arr(M, 6) = CRR(2, i)
Arr(M, 7) = CRR(3, i)
Arr(M, 8) = CRR(4, i)
Arr(M, 9) = CRR(5, i)
Next
ms = ""
myfile = Dir
Loop
Next
[a2:j9999] = ""
[b2].Resize(M, 9) = Arr
Set D = Nothing
Range("b2").CurrentRegion.Sort key1:=[c2], order1:=xlAscending, key2:=[d2], order2:=xlAscending, Header:=xlGuess
Range("A2") = 1
Range("A2").AutoFill Destination:=Range("A2").Resize(M), Type:=xlFillSeries
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|