Sub Ex()
Dim Rng As Range, NameRng As Range, CopyRng As Range, E As Range
Set NameRng = Workbooks("工時整理.xlsm").Sheets(5).[A2:A20].SpecialCells(xlCellTypeConstants) '人名的範圍 或是 完整的路徑檔案名稱
Set Rng = Workbooks("工時整理.xlsm").Sheets(1).[a3]
For Each E In NameRng
'With Workbooks.Open("Q:\" & E & ".xlsx") 'E=人名
With Workbooks.Open(E) '如 E = 完整的路徑檔案名稱
Set CopyRng = .Sheets(1).UsedRange.Offset(3)
Rng.Resize(CopyRng.Rows.Count, CopyRng.Columns.Count).Value = CopyRng.Value
If Rng.End(xlDown).Row = Rows.Count Then
Set Rng = Rng.End(xlDown).End(xlUp).Offset(1)
Else
Set Rng = Rng.End(xlDown).Offset(1)
End If
.Close False
End With
Next
End Sub作者: GBKEE 時間: 2011-11-25 12:09