|
Option Explicit
Sub test()
Dim strFileName$, strPath$, strTxtName$, strTxt$
Dim vResult$(), ar, br, y&, r&
DoApp False
ReDim vResult(1 To 10 ^ 4, 1 To 6)
strPath = ThisWorkbook.Path & "\"
strFileName = Dir(strPath & "*.txt")
Do Until strFileName = ""
strTxtName = Left(strFileName, InStrRev(strFileName, ".") - 1)
strTxt = ReadFromTextFile(ThisWorkbook.Path & "\" & strFileName)
ar = Split(strTxt, vbCr)
For y = 0 To UBound(ar)
br = Split(ar(y), ",")
r = r + 1
vResult(r, 1) = br(0): vResult(r, 3) = br(4)
vResult(r, 4) = br(3): vResult(r, 6) = br(2)
vResult(r, 5) = strTxtName
Next y
strFileName = Dir
Loop
[A1].CurrentRegion.Offset(1).ClearContents
If r Then [A2].Resize(r, UBound(vResult, 2)) = vResult
DoApp
Beep
End Sub
Function DoApp(Optional b As Boolean = True)
With Application
.ScreenUpdating = b
.DisplayAlerts = b
.Calculation = -b * 30 - 4135
End With
End Function
Function ReadFromTextFile$(ByVal strFullName$, Optional ByVal strCharSet$ = "UTF-8")
With CreateObject("ADODB.Stream")
.Type = 2
.Mode = 3
.Charset = strCharSet
.Open
.LoadFromFile strFullName
ReadFromTextFile = .ReadText
.Close
End With
End Function |
评分
-
3
查看全部评分
-
|