|
- Option Explicit
- Sub Demo()
- With Application
- .ScreenUpdating = False
- End With
- Dim ws As Worksheet
- Set ws = ThisWorkbook.Sheets("Sheet1")
- ws.Cells.Clear
- Dim cell As Range
- Set cell = ws.Range("A1")
- Dim folderPath As String
- folderPath = ThisWorkbook.Path
- Dim fileName As String
- fileName = Dir(folderPath & "\*.xls*")
- Do While fileName <> ""
- If fileName <> ThisWorkbook.Name Then
- Dim wb As Workbook
- Set wb = Workbooks.Open(folderPath & "" & fileName)
- wb.Sheets("Sheet1").Range("L2:L7").Copy cell
- wb.Sheets("Sheet1").Range("O2:O7").Copy cell.Offset(0, 1)
- Set cell = ws.Cells(ws.Rows.Count, 1).End(xlUp).Offset(1, 0)
- wb.Close False
- End If
- fileName = Dir
- Loop
- With Application
- .ScreenUpdating = True
- End With
- MsgBox "Done"
- End Sub
复制代码 |
|