|
Sub limonet()
Dim Arr() As Variant, i%, j%, Cn As Object, StrSQL$, Path$, Brr As Variant, F As Object
Path = ThisWorkbook.Path & "\"
Set Cn = CreateObject("Adodb.Connection")
Set Rst = CreateObject("Adodb.recordset")
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
For Each F In CreateObject("scripting.filesystemobject").getfolder(ThisWorkbook.Path & "\数据").Files
i = i + 1
ReDim Preserve Arr(1 To 2, 1 To i): Arr(1, i) = F.Path: Arr(2, i) = F.Name
StrSQL = StrSQL & " Union All Select * From [Excel 12.0;DataBase=" & Arr(1, i) & "].[财政补贴资金公开公示表格模板$A2:I]"
Next F
Brr = Application.Transpose(Application.Transpose(Cn.Execute("Select Distinct [镇(街道)名称] From (" & Mid(StrSQL, 12) & ")").GetRows))
For j = 1 To UBound(Brr)
MkDir Path & Brr(j)
For i = 1 To UBound(Arr, 2)
Cn.Close: StrSQL = "Select * Into Shee1 From [Excel 12.0;DataBase=" & Arr(1, i) & "].[财政补贴资金公开公示表格模板$A2:I] Where [镇(街道)名称]='" & Brr(j) & "'"
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0 XML;Data Source=" & Path & Brr(j) & "\" & Arr(2, i)
Cn.Execute (StrSQL)
Next i
Next j
End Sub |
评分
-
1
查看全部评分
-
|