这代码是要把全部文件都放在同一个文件夹,而且全不文件都齐的情况下才不会出错., 以后有问题自己 看着解决吧, Private Sub LoadData(WorkBookName As String, WorkSheetName As Integer) Dim book1 As Worksheet
Dim book2 As Worksheet Dim i1%
Dim j1% Set book1 = Workbooks(WorkBookName).Sheets(1)
Set book2 = Workbooks("综合分析.xls").Sheets(WorkSheetName) For i1 = 4 To 58
For j1 = 2 To 12
Select Case j1
Case 2 To 4
book2.Cells(i1, j1) = book1.Cells(i1, j1)
Case 5 To 6
book2.Cells(i1, j1 + 1) = book1.Cells(i1, j1)
Case 7 To 9
book2.Cells(i1, j1 + 2) = book1.Cells(i1, j1)
Case 10 To 12
book2.Cells(i1, j1 + 4) = book1.Cells(i1, j1)
End Select
Next
Next
End Sub
Sub xxxx()
Dim SheetName As String
Dim BookName As String
Dim BookPath As String
Dim i As Integer
Dim Arr(1 To 12) As Integer
On Error GoTo Line1 BookPath = ThisWorkbook.Path For i = 1 To 12
Arr(i) = i
Next i Application.ScreenUpdating = False
Application.DisplayAlerts = False For Each y In Arr()
BookName = CStr(y) & "班.xls"
Application.Workbooks.Open BookPath & "\" & BookName
Call LoadData(BookName, CInt(y))
Application.Windows(BookName).Close
Next y
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub Line1:
MsgBox "遇到例外,程序终止" End Sub
|