|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Option Explicit
- Sub test()
- Dim ColumnIndex As Integer, RowIndex As Integer, i As Integer, ss, mh, rq
- Dim arr, brr, Crr, mypath$, myname$, reg As New RegExp
- On Error Resume Next
- With reg
- End With
- mypath = ThisWorkbook.Path & ""
- myname = Dir(mypath & "*.txt")
- With Worksheets("sheet1")
- .Cells.Clear
- End With
- ColumnIndex = 1
- RowIndex = 1
- Do While myname <> ""
- reg.Global = False
- reg.Pattern = "^[a-zA-Z]+\s+(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s+\|\s+[\d\.]+\s+\%\s+([\d\.]+)\s+C\s+$"
- Open mypath & myname For Input As #1
- arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
- Close #1
- ReDim brr(0 To UBound(arr) - 1, 1 To 2)
- ColumnIndex = ColumnIndex + 1
- For i = 0 To UBound(arr) - 1
- ss = Trim(arr(i))
- If Len(ss) > 0 Then
- Set mh = reg.Execute(ss)
- If mh.Count > 0 Then
- brr(i, 1) = mh(0).SubMatches(0)
- brr(i, 2) = Val(mh(0).SubMatches(1))
- End If
- End If
- Next
-
- For i = 0 To UBound(brr)
- reg.Global = True
- reg.Pattern = "-00"
- brr(i, 1) = reg.Replace(brr(i, 1), "")
- If i = 0 Then rq = CDate(brr(0, 1))
- brr(i, 1) = Round((CDate(brr(i, 1)) - rq) * 24 * 60 * 60, 0)
- Next
- With Worksheets("sheet1")
- .Cells(RowIndex, 1) = Split(myname, ".")(0)
- .Cells(1, ColumnIndex) = Split(myname, ".")(0)
- .Cells(RowIndex + 1, 1).Resize(UBound(brr) + 1, 1) = Application.Index(brr, , 1)
- .Cells(RowIndex + 1, ColumnIndex).Resize(UBound(brr) + 1, 1) = Application.Index(brr, , 2)
- RowIndex = .Cells(Rows.Count, 1).End(xlUp).Row + 1
- End With
- myname = Dir
- Loop
- End Sub
复制代码 |
|