以下是引用zliming在2003-3-27 15:13:00的发言: 请教如何将许多EXCEL文件合并成为一个文件(每个文件只有一个SHEELT,而且列是相同的,行则有多有少)
Sub BBGB() ' ' QinZJ ? 2005/12/27 絪? ' TotalFileName = ActiveWorkbook.Name MyPath = ActiveWorkbook.Path & "\" MyPathLong = Len(MyPath) ChDir MyPath Application.ScreenUpdating = False Set fs = Application.FileSearch With fs .LookIn = MyPath .Filename = "*.xls" If .Execute > 0 Then MyCounts = .FoundFiles.Count For i = 1 To MyCounts MyFileName = .FoundFiles(i) If MyFileName <> MyPath & TotalFileName Then Workbooks.Open Filename:=MyFileName Sheets.Copy Before:=Workbooks(TotalFileName).Sheets(1) MyFileNameLong = Len(MyFileName) MyWindowsName = Right(MyFileName, MyFileNameLong - MyPathLong) Windows(MyWindowsName).Activate ActiveWindow.Close End If Next End If End With Application.ActiveWorkbook.Save Application.ScreenUpdating = True End Sub Sub arrange() '蹲羆?虫 '?﹍て MyUnit = 200 MyStart = 4 MySortColumn = "d" TotalName = "Total" '?虫蹲羆 MyCounts = Application.Worksheets.Count Sheets(TotalName).Cells.Delete Sheets(1).Range("A1:IV" & MyStart - 1).Copy Sheets(TotalName).Range("A1:IV" & MyStart - 1).PasteSpecial Paste:=xlValues, Operation:=xlNone Application.ScreenUpdating = False Application.DisplayAlerts = False For i = MyCounts - 1 To 1 Step -1 Sheets(i).Select Range("A" & MyStart & ":IV" & MyUnit).Select Selection.Copy Sheets(TotalName).Select Range("A" & i * MyUnit + MyStart).Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone Sheets(i).Select ActiveWindow.SelectedSheets.Delete Next Columns("A:IV").Select Selection.Sort Key1:=Range(MySortColumn & "2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Cells.EntireColumn.AutoFit Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub |