|
发表于 2011-9-25 11:07
|
显示全部楼层
本楼为最佳答案
回复 雪上人家 的帖子
- Private Sub CommandButton1_Click()
- Dim fs, f, fl, fc, s, fls, flsE
- Dim Wb As Workbook
- Dim She As Object
- Dim Rng As Range
- Set fs = CreateObject("Scripting.FileSystemObject") '创建FileSystemObject对象
- Set f = fs.GetFolder(ThisWorkbook.Path & "\待处理") '创建文件夹对象
- Application.DisplayAlerts = False '临时关闭EXCEL 系统提示
- Set fls = f.Files '取得文件集合
- With ThisWorkbook
- For Each flsE In fls '历遍全部文件
- If InStr(flsE.Name, ".xls") > 0 Then ''避免打开非Excel文件
- Set Wb = Workbooks.Open(flsE) '打开工作薄
- s = s + 1
- Wb.Sheets(1).Copy after:=.Sheets(.Sheets.Count) '复制第一个工作表过来 新建
- Wb.Close False '关闭被打开工作薄
- Set Wb = Nothing '释放对象
- .Sheets(.Sheets.Count).Name = Left(flsE.Name, Len(flsE.Name) - 4) '新工作表名称=工作薄名称
- End If
- Next
- .Save '保存文件
- End With
- Application.DisplayAlerts = True
- MsgBox "共处理了" & s & "工作薄"
- End Sub
复制代码
|
|