|
求大神帮忙更新下我的代码,简化一下合并当前目录下所有工作簿。
Sub 合并当前目录下所有工作簿()
Dim wjm$, c%, pth$, Wb As Workbook, mx As Worksheet
Application.ScreenUpdating = False
Set mx = ThisWorkbook.ActiveSheet
pth = ThisWorkbook.Path & "\"
wjm = Dir(pth & "*.xls*")
Do While wjm = ""
If wjm <> ThisWorkbook.Name Then
Set Wb = Workbooks.Open(pth & wjm)
c = mx.Range("a65336").End(xlUp).Row
If c = 1 Then '防止合并的工作簿第一行空着
Set Rng = Range("a1").CurrentRegion.Offset(1, 0)
Rng.Copy.mx.renge ("a" & c)
Else
Set Rng = Range("a1").CurrentRegion.Offset(3, 0)
Rng.Copy.mx.renge ("a" & c + 1)
End If
Application.DisplayAlerts = False
Wb.Close
Application.DisplayAlerts = True
End If
wjm = Dir
Loop
mx.Columns.AutoFit
Application.ScreenUpdating = True
MsgBox "已完成"
End Sub
|
|