|
请问汇总文件夹下所有工作簿的名称以及第一个表格的某个单元格数值 代码怎么写
- Sub demo()
- Dim strPath As String, strFile As String
- Dim arr(1 To 1000, 1 To 3)
- Dim i As Long
- strPath = ThisWorkbook.Path & Application.PathSeparator & "源文件" & Application.PathSeparator
- strFile = Dir(strPath & "*.xls")
- Application.ScreenUpdating = False
- Do While Len(strFile)
- If strFile <> ThisWorkbook.Name Then
- With GetObject(strPath & strFile)
- Windows(.Name).Visible = True
- i = i + 1
- arr(i, 1) = Left(strFile, InStrRev(strFile, ".") - 1)
- With .Worksheets(1)
- arr(i, 2) = .Range("e2").Value
- arr(i, 3) = .Range("f2").Value
- End With
- .Close False
- End With
- End If
- strFile = Dir
- Loop
- If i > 0 Then
- With Cells(Rows.Count, 1).End(xlUp).Offset(1)
- .Resize(i, 3).Value = arr
- End With
- MsgBox "汇总完成"
- Else
- MsgBox "当前数据目录下无文件可汇总"
- End If
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|