|
- Sub aa()
- Dim d As Object
- Dim d1 As Object, d2 As Object
- Dim ph As String
- Dim sh As Object
- Dim arr(), brr(), crr
- Dim k&, i&, j&, aa, bb, cc
- crr = Array("日期", "当日结存", "风险度")
- Set d = CreateObject("scripting.filesystemobject")
- Set d2 = CreateObject("VBscript.regexp")
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show = True Then
- ph = .SelectedItems(1)
- ph = ph & IIf(Right(ph, 1) <> "", "", "")
- End If
- End With
- With d2
- .Global = True
- .Pattern = "\W+\:\d+\.\d+|\W+\:\d+"
- End With
- With d
- For Each sh In .getfolder(ph).Files
- If .getextensionname(sh) = "txt" Then
- i = i + 1
- Set d1 = .opentextfile(sh)
- Do While Not d1.atendofstream
- k = k + 1
- ReDim Preserve arr(1 To k)
- arr(k) = d1.readline
- aa = Replace(arr(k), " ", "")
- Set cc = d2.Execute(aa)
- For Each bb In cc
- For j = LBound(crr) To UBound(crr)
- If Split(bb, ":")(0) = crr(j) Then
- ReDim Preserve brr(1 To 3, 1 To i)
- If crr(j) = "日期" Then
- brr(1, i) = Format(Split(bb, ":")(1), "0000-00-00")
-
- ElseIf crr(j) = "当日结存" Then
- brr(2, i) = Split(bb, ":")(1)
- Else
- brr(3, i) = Split(bb, ":")(1) & "%"
- End If
- End If
- Next
- Next
- Loop
- End If
- Next
- End With
- Sheet1.Range("a1:c1") = crr
- Sheet1.Range("a2").Resize(UBound(brr, 2), UBound(brr)) = Application.Transpose(brr)
- End Sub
复制代码 |
|