有81个excel表格 要把它们里面的内容全部合并到1个表格里,怎么弄?
发布网友
发布时间:2022-05-25 11:56
我来回答
共1个回答
热心网友
时间:2023-10-24 20:09
用宏。详细可联系我
Sub 汇总()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim exApp As Object, Myexcel As Object
Dim TF As Boolean, i As Integer,n As Integer
On Error Resume Next
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "请选定要处理的Excel文档"
.Filters.Add "excel文档", "*.xls" '暂定扩展名为.xls的excel文档
.AllowMultiSelect = True
If .Show <> -1 Then Exit Sub
Set exApp = GetObject(, "Excel.Application")
If Err <> 0 Then
TF = True
Set exApp = CreateObject("Excel.Application")
End If
For i = 1 To .SelectedItems.Count
Set Myexcel = exApp.Workbooks.Open(.SelectedItems(i))
With Myexcel.Sheets(1)
.UsedRange.Copy [a65536].End(xlUp).Offset(1)
Myexcel.Close False
End With
Next i
n = i
End With
MsgBox "处理完毕,共处理" & n - 1 & "个文档!"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub