vba怎么读取多个excel文件代码
发布网友
发布时间:2022-04-24 23:32
我来回答
共1个回答
热心网友
时间:2023-10-14 19:51
Sub 按钮2_Click()
Application.ScreenUpdating = False
Set cnn = CreateObject("adodb.connection")
[a2:l65536].ClearContents
h = 2
f = Dir(ThisWorkbook.Path & "\*.xls?")
Do While f > ""
If f <> ThisWorkbook.Name Then
cnn.Open "provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=yes';data source=" & ThisWorkbook.Path & "" & f
Sql = "select * from [sheet1$A1:C1000]"
Cells(h, 1).CopyFromRecordset cnn.Execute(Sql)
h = Cells(Rows.Count, 1).End(xlUp).Row + 1
cnn.Close
End If
f = Dir
Loop
Application.ScreenUpdating = True
End Sub