|
- Sub test3() '比你的电脑快,江哥换机吧
- Dim strFileName$, strPath$, n As Byte
- Dim vResult$(), ar, br, y&, x&, j&, r&
- Dim t As Single
- Application.ScreenUpdating = False
- t = Timer
- ReDim vResult(1 To 6000, 8)
- strPath = ThisWorkbook.Path & "\"
- strFileName = Dir(strPath & "*.txt")
-
- Do Until strFileName = ""
- n = FreeFile
- Open strPath & strFileName For Input As #n
- ar = Split(StrConv(InputB(LOF(n), #n), vbUnicode), vbCrLf)
- Close #n
- r = r + 1
- vResult(r, UBound(vResult, 2)) = Mid(strFileName, 4, 6)
- For y = UBound(ar) - 2 To 1 Step -1 '倒着判断,这样速度可能有所提升,以下为猜测
- 'If Split(ar(y), vbTab)(0) > Split(ar(y - 1), vbTab)(0) Then
- If Left(ar(y), 10) > Left(ar(y - 1), 10) Then '比上面的split 快点
- br = Split(ar(y), vbTab)
- For j = 0 To UBound(br)
- vResult(r, j) = br(j)
- Next j
- Exit For '满足则退出循环
- End If
- Next y
- strFileName = Dir
- Loop
- With Sheets("Sheet1")
- .[a2].Resize(r, UBound(vResult, 2) + 1) = vResult
- .Range("K1") = Timer - t ' 输出时间
- End With
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
评分
-
3
查看全部评分
-
|