1.我試了您的方法,但卻出現 "陣列索引超出範圍 (錯誤 9)",程式碼如下:
Sub 統計()
Dim Wb As Workbook
For Each Wb In Workbooks
If Wb.Name <> "統計.xls" Then '排除 "統計.xls"
Wb.Sheets("Sheet2").Copy After:=Workbooks("統計.xls").Sheets(2) '錯誤9
ActiveSheet.Name = Replace(Wb.Name, ".xls", "")
End If
Next
Workbooks("統計.xls").Activate
End Sub
2.我另外又加了路徑,但卻出現 "型態不符合 (錯誤 13)",程式碼如下:
Sub 統計()
Dim MyBook, Wb As Workbook, MyPath As Long
Set MyBook = ThisWorkbook
MyPath = MyBook.Path & "\" '型態不符
With Workbooks.Open(MyPath & "*.xls")
For Each Wb In Workbooks
If Wb.Name <> "統計.xls" Then
Wb.Sheets("Sheet2").Copy after:=MyBook.Sheets(Sheets.Count)
ActiveSheet.Name = Replace(Wb.Name, ".xls", "")
End If
Next
End With
Workbooks("統計.xls").Activate
End Sub
3.我是要將不同檔名的檔案匯入一個excel檔內,再來作資料處理。作者: Hsieh 時間: 2011-9-30 19:30
Sub ex()
Dim MyPath As String, fs As String, MySht As Worksheet