|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim Conn As Object, rs As Object, Sht As Worksheet
- Dim strConn As String, ar() As String, i As Integer
- Set Conn = CreateObject("ADODB.Connection")
-
- If Application.Version < 12 Then
- strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source="
- Else
- strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source="
- End If
- Conn.Open strConn & ThisWorkbook.FullName
-
- For Each Sht In Worksheets
- With Sht
- If .Name <> "汇总" Then
- i = i + 1
- ReDim Preserve ar(1 To i)
- ar(i) = "SELECT '" & .Name & "区领导批示件' AS 类别,分管领导,牵头科室,经办人 FROM [" & .Name & "$" & .Range("A1").CurrentRegion.Address(0, 0) & "]"
- End If
- End With
- Next
-
- Set rs = Conn.Execute(Join(ar, " UNION ALL "))
- With Worksheets("汇总")
- .Range("A1").CurrentRegion.Offset(1).ClearContents
- For i = 0 To rs.Fields.Count - 1
- .Range("A1").Offset(0, i) = rs.Fields(i).Name
- Next
- .Range("A2").CopyFromRecordset rs
- End With
-
- Set rs = Nothing
- Conn.Close
- Set Conn = Nothing
- Beep
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|