合并選擇的多個(gè)excel文件下所有的工作表合并到一個(gè)工作簿里
Sub test()
Dim str()
Dim i As Integer
Dim wb, wb1 As Workbook
Dim sht As Worksheet
On Error Resume Next '加上以后防止點(diǎn)了取消發(fā)生的錯(cuò)誤
Set wb1 = ActiveWorkbook
Set sht1 = ActiveSheet
On Error Resume Next
str = Application.GetOpenFilename("Excel數(shù)據(jù)文件,*.xls*", , , ,?True)
'?true?代表可多選工作簿"Excel數(shù)據(jù)文件,*.xls*"?顯示類型為xls的文件
? ? For i = LBound(str) To UBound(str)
'??LBound(str)?數(shù)組下限UBound(str)?數(shù)組上限
? ? ? ? Set wb = Workbooks.Open(str(i))
? ? ? ? For Each sht In wb.Sheets
? ? ? ? ? ? sht.Copy after:=wb1.Sheets(wb1.Sheets.Count)
? ? ? ? ? ? wb1.Sheets(wb1.Sheets.Count).Name = Split(wb.Name, ".")(0) & sht.Name
? ? ? ? Next
? ? ? ? wb.Close
? ? Next
End Sub