用你的代码修改一下: Sub 合并工作簿() Dim FilesToOpen Dim x As Integer On Error GoTo ErrHandler Application.ScreenUpdating = False FilesToOpen = Application.GetOpenFilename _ (FileFilter:="Microsoft Excel Files (*.xls), *.xls", _ MultiSelect:=True, Title:="Files to Merge") If TypeName(FilesToOpen) = "Boolean" Then MsgBox "No Files were selected" GoTo ExitHandler End If x = 1 While x <= UBound(FilesToOpen) Set wb = Workbooks.Open(Filename:=FilesToOpen(x)) With wb .Sheets(1).Copy after:=ThisWorkbook.Sheets _ (ThisWorkbook.Sheets.Count) ActiveSheet.Name = Replace(wb.Name, ".xls", "") '工作表命名 .Close False '不保存关闭工作簿 End With x = x + 1 Wend ExitHandler: Application.ScreenUpdating = True Exit Sub ErrHandler: MsgBox Err.Description Resume ExitHandler End Sub
|