|
- Sub Opiona()
- '禁止系统刷屏?触发其他事件等
- 'On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
- Application.ScreenUpdating = False '//关闭屏幕刷新
- Application.DisplayAlerts = False '//关闭系统提示
- Application.EnableEvents = False '//禁止触发其他事件
- t = Timer '//开始时间
- Set SHX = Worksheets("动力厂A产品台账")
- SHX.Range("A2:G1048576").ClearContents
- STRNAME = SHX.Range("M4").Value
- SHEETNAME = SHX.Range("M5").Value
- KSH = SHX.Range("M6").Value
- JSH = SHX.Range("M7").Value
- ICOUNT = JSH - KSH - 1
- COUNTCOL = SHX.Range("M100").End(3).Row - 7 + 2
- FileArr = FileAllArr(ThisWorkbook.Path, "*" & STRNAME & "*.xls?", ThisWorkbook.Name, True, False)
- For I = 0 To UBound(FileArr)
- STRMONTH = Mid(GetPathFromFileName(FileArr(I)), 1, InStr(GetPathFromFileName(FileArr(I)), STRNAME) - 1)
- Set WB = Workbooks.Open(FileArr(I))
- Set SHW = WB.Sheets(SHEETNAME)
- ReDim ARR(1 To ICOUNT, 1 To COUNTCOL)
- For IROW = 1 To ICOUNT
- ARR(IROW, 1) = STRMONTH
- ARR(IROW, 2) = STRNAME
- For ICOL = 3 To COUNTCOL
- ARR(IROW, ICOL) = SHW.Range(SHX.Range("M" & ICOL - 3 + 8).Value & IROW + KSH - 1).Value
- Next
- Next
- WB.Close False '//保存
- LASTROW = SHX.Range("A1048576").End(3).Row + 1
- SHX.Range("A" & LASTROW).Resize(UBound(ARR, 1), UBound(ARR, 2)) = ARR '//(0 TO X)的数组行列都要+1,(1 TO X) 的不要
- Next
-
- Application.EnableEvents = True '// '//恢复触发其他事件
- Application.ScreenUpdating = True '//恢复屏幕刷新
- Application.DisplayAlerts = True '//恢复系统提示
- MsgBox "符合條件的文件個數: " & UBound(FileArr) + 1 & vbCrLf & vbCrLf & "一共用时:" & Format(Timer - t, "#0.0000") & " 秒", , "北极狐提示!!" '//提示所用时间
- End Sub
复制代码 |
|