|
|
高家三少 发表于 2013-4-28 17:25 
感谢版主大大!!!测了可以,不过我想把e2换成h11 却提示超出电子数据单元范围 - 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 & "].[对账$h11:h11]"
- 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
复制代码 |
|