运行环境,excel的vba,开启方法自行百度
合并条件,每个文件合并第一个表,用文件名命名表名
Sub 合并工作簿单()
Dim str As String
Dim wb As Workbook
Dim lj As String
lj = InputBox("请输入文件路径,格式c:\a")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
str = Dir(lj & "*.xls*")
For i = 1 To 100
Set wb = Workbooks.Open(lj & "" & str)
Application.DisplayAlerts = False
wb.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0)
wb.Close
str = Dir
If str = "" Then
Exit For
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Next
End Sub
Sub 合并工作簿单()
Dim str As String
Dim wb As Workbook
Dim lj As String
lj = InputBox("请输入文件路径,格式c:\a")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
str = Dir(lj & "\*.xls*")
For i = 1 To 100
Set wb = Workbooks.Open(lj & "\" & str)
Application.DisplayAlerts = False
wb.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = Split(wb.Name, ".")(0)
wb.Close
str = Dir
If str = "" Then
Exit For
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Next
End Sub
网友评论