|
|
汇总每个工作簿中的对账表的E2单元格?如果是请测试:- Sub 宏1()
- Dim cnn As Object
- Dim SQL$, MyFile$, Mypath$, n&, arr(1 To 10000, 1 To 2)
- Mypath = ThisWorkbook.Path & ""
- MyFile = Dir(Mypath & "*.xlsx")
- Do While MyFile <> ""
- n = n + 1
- If n = 1 Then
- Set cnn = CreateObject("ADODB.Connection")
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=no';Data Source=" & Mypath & MyFile
- SQL = "select f1 from [对账$e2:e2]"
- Else
- SQL = "select f1 from [Excel 12.0;hdr=no;Database=" & Mypath & MyFile & "].[对账$e2:e2]"
- End If
- arr(n, 1) = Replace(MyFile, ".xlsx", "")
- arr(n, 2) = cnn.Execute(SQL)(0)
- MyFile = Dir()
- Loop
- [a1].CurrentRegion.Offset(1).ClearContents
- [a2].Resize(n, 2) = arr
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|