标题:老师新来的请多多关照,求问题
取消只看楼主
wjgzy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-3-3
结帖率:0
已结贴  问题点数:20 回复次数:1 
老师新来的请多多关照,求问题
有大量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
搜索更多相关主题的帖子: 老师 txt Sub If Then 
2019-03-03 13:01
wjgzy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-3-3
得分:0 
就是怎么能让这些代码运行工作,我不懂,求指教
2019-03-03 13:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-493394-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.147186 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved