|
本帖最后由 cbtaja 于 2012-3-12 14:36 编辑
3楼的代码有个小问题,改正如下:
Sub 合并多工作薄的第1个表格中的数据()
Dim MyFile, MyPath, MyName, Cbook, Sht, r, n, arr
Application.ScreenUpdating = False
On Error Resume Next
n = 2
MyPath = ThisWorkbook.Path & "\"
MyFile = Dir(MyPath & "*.xlsx")
Do While MyFile <> ""
Set Cbook = GetObject(MyPath & MyFile)
With Cbook.Sheets("sheet1")
r = .[a65536].End(3).Row
arr = .Range("A2:D" & r)'原来是Sht.Range("A2:D" & r),其中的变量Sht是多余的。
End With
With ThisWorkbook.Sheets(1)
.Cells(n, 1).Resize(r - 1, 4) = arr
n = n + r-1
End With
Cbook.Close False
MyFile = Dir
Loop
End Sub
|
|