|
Public Sub GetTxt()
Dim Str1 As String, Fname As String, MyFile As String
Dim fNumber As Long, r As Long
Dim MyPath As String
Dim Arr, Sp
r = 1
On Error Resume Next
Range("A1").CurrentRegion.Offset(1).ClearContents
MyPath = ThisWorkbook.Path & "\提取文本内容\"
Fname = Dir(MyPath & "*.txt")
Do While Fname <> ""
MyFile = Fname
Fname = MyPath & Fname
fNumber = FreeFile
Open Fname For Input As fNumber
ReDim Arr(1 To 1, 1 To 9)
Arr(1, 1) = VBA.Split(MyFile, ".")(0)
Do
Line Input #fNumber, Str1
If InStr(Str1, ";Logged:") > 0 Then
Str1 = Mid(Str1, 9)
Sp = VBA.Split(Str1, " at ")
Arr(1, 2) = Sp(0)
Arr(1, 3) = Sp(1)
End If
If Left(Str1, 5) = ";Min:" Then
Str1 = Split(Str1, ":")(1)
Arr(1, 4) = VBA.Replace(Str1, "mJ", "")
End If
If Left(Str1, 5) = ";Max:" Then
Str1 = Split(Str1, ":")(1)
Arr(1, 5) = VBA.Replace(Str1, "mJ", "")
End If
If InStr(Str1, ";Average:") > 0 Then
Str1 = Split(Str1, ":")(1)
Arr(1, 6) = VBA.Replace(Str1, "mJ", "")
End If
If InStr(Str1, ";Std.Dev.:") > 0 Then
Str1 = Split(Str1, ":")(1)
Arr(1, 7) = VBA.Replace(Str1, "mJ", "")
End If
If InStr(Str1, ";Overrange:") > 0 Then
Arr(1, 8) = Split(Str1, ":")(1)
End If
If InStr(Str1, ";Total Pulses:") > 0 Then
Arr(1, 9) = Split(Str1, ":")(1)
Exit Do
End If
Loop Until EOF(fNumber)
Close #fNumber
r = r + 1
Range("A" & r).Resize(, 9) = Arr
Fname = Dir
Loop
End Sub
|
|