- 积分:1
- 财富值:0.0
- 身份:普通用户
Application.ScreenUpdating = False
a = ThisWorkbook.Path & "\"
mz = Dir(a & "*.xls")
Do
If mz <> "汇总表.xls" Then
Workbooks.Open (a & mz)
k = k + 1
r = Application.CountA(Workbooks(mz).Sheets(1).Columns(1)) + 1
zr = Application.CountA(Workbooks(1).Sheets(1).Columns(1)) + 3
Workbooks(mz).Sheets(1).Range("a5:k" & r).Copy Workbooks(1).Sheets(1).Cells(zr, 1)
Workbooks(mz).Close True
End If
mz = Dir
Loop Until mz = ""
Workbooks(1).Sheets(1).Cells(4, 1).Resize(1, 4) = k
Workbooks(1).Sheets(1).Cells(4, 1).Resize(1, 4).NumberFormat = "@"
Application.ScreenUpdating = True
End Sub
Sub 清空()
zr = Application.CountA(Workbooks(1).Sheets(1).Columns(1)) + 1
Sheets(1).Range("a4:k" & zr).ClearContents
End Sub
- 积分:99
- 财富值:250
- 身份:普通用户
回复:楼主
这是个遍历文件 进行汇总功能,我帮你注释一下:
你需要详细了解dir 函数的功能:http://wenku.baidu.com/link?url=aYqDqt3VQbb8LNDbf9BnSUbSXdxIJEUuUI9OiDtQWwZIHOLwpcLaFVhk2wYZgnXUzyRy2ne6vvSDASTC9TrFkuuMPue6rh1lvCtXbOIvaE7
Sub 汇总()
Application.ScreenUpdating = False
a = ThisWorkbook.Path & "\"
mz = Dir(a & "*.xls") '第一次查找xls文件
Do
If mz <> "汇总表.xls" Then '不是 汇总表.xls 才进行汇总
Workbooks.Open (a & mz)
k = k + 1
r = Application.CountA(Workbooks(mz).Sheets(1).Columns(1)) + 1
zr = Application.CountA(Workbooks(1).Sheets(1).Columns(1)) + 3
Workbooks(mz).Sheets(1).Range("a5:k" & r).Copy Workbooks(1).Sheets(1).Cells(zr, 1) '拷贝 查找到的这个文件的单元格区域到 同一个工作表中
Workbooks(mz).Close True ’关闭查找到的这个文件
End If
mz = Dir '第二次查找文件
Loop Until mz = "" '直到查找完全部的xls文件
Workbooks(1).Sheets(1).Cells(4, 1).Resize(1, 4) = k
Workbooks(1).Sheets(1).Cells(4, 1).Resize(1, 4).NumberFormat = "@" ‘设置为文本格式
Application.ScreenUpdating = True
End Sub
Sub 清空()
zr = Application.CountA(Workbooks(1).Sheets(1).Columns(1)) + 1
Sheets(1).Range("a4:k" & zr).ClearContents
End Sub