|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
原帖由 terryzj 于 2011-3-5 15:52 发表
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & Mypath & MyFile
这句话
我的文件夹中即有2007版本的文件.xlsm,又有2003版本的文件.xls
似乎:Microsoft.ACE.OLEDB ...
稍加修改就可以了,不要自连接,cnn连接到xls和xlsx文件都可以查询到超过65536行记录(针对xlsx文件):
Sub Macro1()
Dim cnn As Object, SQL$, Mypath$, MyFile$, n%
Set cnn = CreateObject("adodb.connection")
Mypath = ThisWorkbook.Path & "\"
MyFile = Dir(Mypath & "*.xls*")
Do While MyFile <> ""
' If MyFile <> ThisWorkbook.Name Then
If Right(MyFile, 4) <> "xlsm" Then '不查询启用宏的工作簿(xlsm)
n = n + 1
If n = 1 Then
cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & Mypath & MyFile
SQL = "select* from [Sheet1$] where Project is not null"
Else
SQL = SQL & " union all select * from [Excel 12.0;Database=" & Mypath & MyFile & "].[Sheet1$] where Project is not null"
End If
End If
MyFile = Dir()
Loop
[a1].CurrentRegion.Offset(1).ClearContents
[a2].CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
End Sub
[ 本帖最后由 zhaogang1960 于 2011-3-5 16:42 编辑 ] |
|