|
本帖最后由 yuan1987 于 2013-9-30 23:04 编辑
遍历文件夹,查找名为“基本情况表”的Excel文件,取查找到“基本情况表”中“开始”表的的A2,B2单元格数据,依次填充到归类表中统计表的A列,B列,最终结果见附件
- Sub 汇总()
- Application.ScreenUpdating = False
- Dim lj As String, m, n
- Dim dirname As String
- Dim nm As String
- Dim wb As Workbook
- Dim i As Integer
- On Error Resume Next
- With Application
- .ScreenUpdating = False
- .DisplayAlerts = False
- .EnableEvents = False
- .Calculation = xlCalculationManual
- End With
- lj = ThisWorkbook.Path
- nm = ThisWorkbook.Name
- dirname = Dir(lj & "\*.xlsx")
- Cells.Clear
- Do While dirname <> ""
- If dirname <> nm Then
- Set wb = Workbooks.Open(Filename:=lj & "" & dirname, UpdateLinks:=False, ReadOnly:=True)
- If Not wb Is Nothing Then
- With wb
- If Len(.Sheets("开始").Name) = 0 Then
- Else
- i = .Sheets("开始").Range("A65536").End(xlUp).Row
- ThisWorkbook.Sheets("统计表").Cells(m, 1) = .Sheets("开始").Cells(2, 1).Value
- ThisWorkbook.Sheets("统计表").Cells(n, 2) = .Sheets("开始").Cells(2, 1).Value
- End If
- .Close False
- End With
- Set wb = Nothing
- End If
- End If
- dirname = Dir
- Loop
- With Application
- .ScreenUpdating = True
- .DisplayAlerts = True
- .EnableEvents = True
- .Calculation = xlCalculationAutomatic
- End With
- MsgBox "OK"
- End Sub
复制代码
|
|