老师新来的请多多关照,求问题
有大量txt,需要批量提取txt文本中几个固定字段的内容,最后分列输出到excel或txt,求代码我看到一段别人回答的代码,不懂怎么用,求老师指教,一点不懂程序
Sub test()
Dim f As String, arr(1 To 60000, 1 To 3), jL As Long
Dim mPath As String, fn As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "----------------------选择Txt文件所在的文件夹!-----------------"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then MsgBox "你放弃了操作!": Exit Sub
mPath = .SelectedItems(1)
End With
jL = 0
fn = Dir(mPath & "\*.txt")
Do While fn <> ""
Open fn For Input As #1
jL = jL + 1
Do While Not EOF(1)
Line Input #1, s
If InStr(s, "客户号 Client ID:") Then arr(jL, 1) = Val(Replace(Mid(s, 17, 20), " ", ""))
If InStr(s, "保证金占用 Margin Occupied") Then arr(jL, 2) = Val(Replace(Right(s, 20), " ", ""))
If InStr(s, "可用资金") Then arr(jL, 3) = Val(Replace(Right(s, 20), " ", ""))
Debug.Print s
Loop
Close #1
fn = Dir
Loop
ActiveSheet.UsedRange.ClearContents
[a1:C1] = [{"客户号","保证金占用","可用资金"}]
[a2].Resize(jL, 3) = arr
End Sub