导入多个文本文件

我有一个目录(.hne文件)中的多个文本文件,我想导入数据到Excel中,但只有行11后的数据。下面的代码导入数据,但它只能做一个文件一次我的文本文件有四个由空格分隔的列时,它导入到Excel将它全部放在一列。

有人可以帮我清理这个代码,我一定会很感激。 此外,我有很多文本文件,它可能会超过一个activesheet的最大行,它可能会自动将其余的数据放在另一张表。

Private Sub() Dim FilePath As String Dim i, j As Integer i = 0 j = 1 FilePath = ThisWorkbook.Path & "\201412010030.hne" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(FilePath, 1) Do Until objFile.AtEndOfStream strline = objFile.ReadLine 'If objFile.AtEndOfStream = True Then 'MsgBox strLine 'End If i = i + 1 If i > 11 Then Cells(j, 1).Value = strline j = j + 1 End If Loop objFile.Close End Sub 

这是一个文件im试图导入的例子

  TRIAXYS BUOY DATA REPORT - TAS05642 VERSION = 6a.02.08 TYPE = HNE DATE = 2014 Dec 01 01:00 NUMBER OF POINTS = 2072 TIME OF FIRST POINT (s) = 90.63 SAMPLE INTERVAL (s) = 0.78 COLUMN 1 = TIME (s) COLUMN 2 = HEAVE (m) COLUMN 3 = DSP NORTH (m) COLUMN 4 = DSP EAST (m) 90.63 -0.42 0.53 -0.34 91.41 0.14 0.72 -0.39 92.19 0.45 0.61 -0.47 92.98 0.75 0.26 -0.11 93.76 1.04 -0.26 0.53 94.54 0.58 -0.68 0.94 95.32 -0.13 -0.67 1.00 96.10 -0.26 -0.47 0.90 96.88 -0.50 -0.31 0.50 97.66 -0.94 -0.22 -0.14 

下面的代码工作得很好,我唯一需要做的就是导入第11行之后的所有数据。

 Sub ReadFilesIntoActiveSheet() Dim fso As FileSystemObject Dim folder As folder Dim file As file Dim FileText As TextStream Dim TextLine As String Dim Items() As String Dim i As Long Dim cl As Range ' Get a FileSystem object Set fso = New FileSystemObject ' get the directory you want Set folder = fso.GetFolder("C:\hnefiles") ' set the starting point to write the data to Set cl = ActiveSheet.Cells(1, 1) ' Loop thru all files in the folder For Each file In folder.Files ' Open the file Set FileText = file.OpenAsTextStream(ForReading) ' Read the file one line at a time Do While Not FileText.AtEndOfStream TextLine = FileText.ReadLine ' Parse the line into | delimited pieces Items = Split(TextLine, " ") ' Put data on one row in active sheet cl.Resize(1, UBound(Items) - LBound(Items) + 1).Value = Items ' Move to next row Set cl = cl.Offset(1, 0) Loop ' Clean up FileText.Close Next file Set FileText = Nothing Set file = Nothing Set folder = Nothing Set fso = Nothing End Sub