|
- Sub 各月报类汇总()
- Dim cnn As Object, rs As Object, rst As Object, SQL$, s$, wn$, p$, f$, m&, sh As Worksheet
- p = ThisWorkbook.Path & ""
- f = Dir(p & "*.xls*")
- Do While f <> ""
- If Right(f, 5) = ".xlsx" Or Right(f, 4) = ".xls" Then
- wn = Split(f, ".")(0)
- On Error Resume Next
- Set sh = Worksheets(wn)
- On Error GoTo 0
- If Not sh Is Nothing Then
- sh.UsedRange.ClearContents
- Set cnn = CreateObject("adodb.connection")
- cnn.Open "Provider=Microsoft.ace.OLEDB.12.0;Extended Properties=excel 12.0;Data Source=" & p & f
- Set rs = cnn.OpenSchema(20)
- m = 0
- Do Until rs.EOF
- If rs.Fields("TABLE_TYPE") = "TABLE" Then
- s = Replace(rs("TABLE_NAME").Value, "'", "")
- If Right(s, 1) = "$" Then
- m = m + 1
- SQL = "select * from [" & s & "] where 地市='汕头'"
- Set rst = cnn.Execute(SQL)
- If m = 1 Then
- For i = 1 To rst.Fields.Count
- sh.Cells(1, i) = rst.Fields(i - 1).Name
- Next
- End If
- sh.Range("A" & sh.Rows.Count).End(xlUp).Offset(1).CopyFromRecordset rst
- End If
- End If
- rs.MoveNext
- Loop
- End If
- End If
- f = Dir()
- Loop
- rs.Close
- rst.Close
- cnn.Close
- Set rs = Nothing
- Set rst = Nothing
- Set cnn = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|