|
发表于 2017-7-11 12:48
|
显示全部楼层
本楼为最佳答案
本帖最后由 chart888 于 2017-7-11 12:50 编辑
- Option Explicit
- Sub test()
- Dim mypath, myfile, wb, r, j, i
- Range("A2:A" & Rows.Count).Clear
- Application.ScreenUpdating = False
- mypath = ThisWorkbook.Path & "" '找到当前工作簿的路径
- myfile = Dir(mypath & "*.xls*") '遍历当前路径下的工作簿
- Do While myfile <> "" '当找到的文件不为空时
- If myfile <> ThisWorkbook.Name Then '当找到的文件不是本工作簿时
- Set wb = GetObject(mypath & myfile) '利用GetObject取得数据
- With wb.Sheets(1) '对wb的sheet1进行操作
- r = ThisWorkbook.ActiveSheet.Range("A65536").End(xlUp).Row + 1
- .Range("G8:G25").Copy ThisWorkbook.ActiveSheet.Cells(r, 1)
- End With
- wb.Close '别忘了关掉,要不然越开越多电脑就瘫痪了
- End If
- myfile = Dir '去找下一个工作簿
- Loop
- r = ThisWorkbook.ActiveSheet.Range("A65536").End(xlUp).Row
- For j = r To 1 Step -1
- If Cells(j, 1) = "" Then
- Rows(j).Delete
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
查看全部评分
|