Sub Ex()
Dim MergePath As String, FS As String, Rng As Range
MergePath = "C:\Documents and Settings\choikeun\Desktop\New" '合併檔案的資料夾
FS = Dir(MergePath & "*.xls") '尋找 xls 檔案
If FS <> "" Then
Set Rng = Workbooks.Add(xlWBATWorksheet).Sheets(1).[a1] '新開的檔案(只有一張工作表)工作表的A1
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Do
With Workbooks.Open(MergePath & FS)
.Sheets(1).UsedRange.Copy Rng 'MergePath & 中工作表資料 複製到Rng
.Close
End With
FS = Dir '繼續尋找(MergePath & "*.XLS")
Set Rng = Rng.End(xlDown).Offset(1) '重設Rng 為往下到最後有資料的儲存格下一個空白之儲存格
Loop While FS <> ""
Application.DisplayAlerts = False
Rng.Parent.Parent.SaveAs MergePath & "合併.xls" '合併檔存檔
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Else
MsgBox MergePath & " 沒有 xls 檔案"
End If
End Sub
我已經修改了,,但是都不行...........作者: GBKEE 時間: 2012-7-23 17:05