|
Public Sub qs() '2024/7/20多工作簿合并
Application.ScreenUpdating = False: Application.DisplayAlerts = False
Dim wb As Workbook, xb As Workbook, pt As String, m, x
Set wb = ThisWorkbook
na = wb.Name
Set FSO对象 = CreateObject("Scripting.FileSystemObject")
pt = ThisWorkbook.Path & "\" '相对路径及文件夹名称
Set 文件夹 = FSO对象.GetFolder(pt)
For Each i In 文件夹.Files '循环文件下的每一个文件
If VBA.InStr(i, na) < 1 Then
文件名 = FSO对象.GetBaseName(i)
Set xb = Workbooks.Open(i, 0)
m = m + 1
arr = xb.Sheets(1).Range("a1").CurrentRegion
If m = 1 Then
wb.Sheets("汇总").Range("a1").Resize(UBound(arr), UBound(arr, 2)) = arr
Else
x = wb.Sheets("汇总").Cells(1, 1000).End(xlToLeft).Column + 2
wb.Sheets("汇总").Cells(1, x).Resize(UBound(arr), UBound(arr, 2)) = arr
End If
xb.Close
End If
Next
Set xb = Nothing
Set wb = Nothing
Application.ScreenUpdating = True: Application.DisplayAlerts = True
MsgBox "完毕!"
End Sub
|
评分
-
1
查看全部评分
-
|