利用VBA批量导入TXT或LOG文件,并完成筛选汇总

Sub 批量导入TXT或LOG并完成汇总()
    Dim Fs As Object, Ft As Object
    Set Fs = CreateObject("Scripting.FileSystemObject")
    filePath = ThisWorkbook.Path & "\"
    fileName = Dir(filePath & "*.log", vbNormal)
    Worksheets("SHEET1").Cells.Clear
    Worksheets("SHEET1").Range("A1:D1") = Array("ENBIP", "MO", "参数", "值")
    N = 1
    Do While fileName <> ""
      Set Fs = CreateObject("Scripting.FileSystemObject")
      Set Ft = Fs.opentextfile(filePath & fileName)
       Do
        TEXTLINE = Ft.ReadLinE
        If InStr(1, TEXTLINE, "EUtranCell") > 0 Then
        N = N + 1
        strn = Split(TEXTLINE, " ")
        Count = UBound(strn)
        If Count = 2 Then
           Worksheets("SHEET1").Cells(N, 1) = fileName
           Worksheets("SHEET1").Cells(N, 2) = strn(0)
           Worksheets("SHEET1").Cells(N, 3) = strn(1)
           Worksheets("SHEET1").Cells(N, 4) = strn(2)
         ElseIf Count = 3 Then
         
           Worksheets("SHEET1").Cells(N, 1) = fileName
           Worksheets("SHEET1").Cells(N, 2) = strn(0)
           Worksheets("SHEET1").Cells(N, 3) = strn(1)
           Worksheets("SHEET1").Cells(N, 4) = strn(3)
          End If
        End If
        Loop Until Ft.atendofstream 'Ft.atendofline 'Ft.AtEndOfLine
       Set Fs = Nothing
       Set Ft = Nothing
       Close #1
       fileName = Dir
     Loop
 MsgBox ("已完筛选、合并操作!")
End Sub

输出结果:

利用VBA批量导入TXT或LOG文件,并完成筛选汇总

上一篇:.net Gridview空数据的时候显示表头


下一篇:javascript – Firefox浏览器无法识别table.cells吗?