|
Sub limonet()
Dim Cn As Object, Cat As Object, Fld As Object, F As Object, ObjSheet As Object
Dim Path$, TmpPro$, Pro$, StrSQL$, TmpArr As Variant
Path = ThisWorkbook.Path & "\纳税情况"
Set Cat = CreateObject("ADOX.Catalog")
Set Cn = CreateObject("ADODB.Connection")
TmpPro = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=NO';Data Source="
Pro = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
Set Fld = CreateObject("Scripting.FileSystemObject").GetFolder(Path)
For Each F In Fld.Files
Cat.ActiveConnection = Pro & F.Path
For Each ObjSheet In Cat.tables
If Not ObjSheet.Name Like "*FilterDatabase" And ObjSheet.Type = "TABLE" Then
Cn.Open TmpPro & F.Path
StrSQL = "Select * From [" & ObjSheet.Name & "A1:A1]"
TmpArr = Cn.Execute(StrSQL).getrows
StrSQL = "Select '" & Split(F.Name, ".xls")(0) & "' as F1,'" & Mid(TmpArr(0, 0), 15, 18) & "' as F2,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10 From [" & ObjSheet.Name & "A3:L]"
Sheet1.Range("A" & Sheet1.Range("A9999").End(xlUp).Row + 1).CopyFromRecordset Cn.Execute(StrSQL & " Where F1<>'合计'")
Sheet2.Range("A" & Sheet2.Range("A9999").End(xlUp).Row + 1).CopyFromRecordset Cn.Execute(StrSQL & " Where F1='合计'")
Cn.Close
End If
Next ObjSheet
Next F
End Sub
|
|