如何将多个文件合并在一个excel文件中?
2个回答
展开全部
Sub test()Dim str As StringDim wb As WorkbookDim sht As Worksheetstr = Dir("E:\data\*.xls*")For i = 1 To 100
Set wb = Workbooks.Open("E:\data\" & str) '文件汇总
For Each sht In wb.Sheets
sht.Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count) 'ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0) & sht.Name
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = sht.Name Next
wb.Close str = Dir
If str = "" Then
Exit For
End If
NextEnd Sub
Set wb = Workbooks.Open("E:\data\" & str) '文件汇总
For Each sht In wb.Sheets
sht.Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count) 'ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0) & sht.Name
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = sht.Name Next
wb.Close str = Dir
If str = "" Then
Exit For
End If
NextEnd Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询