|
- '*********************************
- '******* 北极狐工作室出品 ******
- '******* QQ:14885553 ******
- '*********************************
- Sub Opiona()
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- t = Timer '//开始时间
-
- Kill ThisWorkbook.Path & "\需要得到的结果.xlsx" '//先删除以前的结果
-
- FileArr = FileAllArr(ThisWorkbook.Path, "*.xls?", ThisWorkbook.Name, True, False) '//获得文件列表,见函数解释
- Set WB = Workbooks.Add '新建一个工作簿
- Set SHX = WB.Sheets(1)
-
- For I = 0 To UBound(FileArr)
- Rem '//工作簿的问题,无法使用SQL,而且还要以修复形式打开
- Set WBOPEN = Workbooks.Open(Filename:=FileArr(I), CorruptLoad:=xlExtractData)
- Set SHOPEN = WBOPEN.Sheets(1)
- If I = 0 Then '//粘贴标题
- SHOPEN.Range("A1:CZ1").Copy SHX.Range("A1")
- End If
- IROW = SHX.Range("A1048576").End(3).Row + 1
- LASTROW = SHOPEN.Range("A1048576").End(3).Row
- SHOPEN.Range("A2:CZ" & LASTROW).Copy SHX.Range("A" & IROW) '//复制数据,假设标题顺序一致
-
- WBOPEN.Close False
- Next I
- WB.SaveAs ThisWorkbook.Path & "\需要得到的结果.xlsx" '另存为指定文件名
- WB.Close True
-
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
|