如何打开多个文本文件到一个Excel工作表,但跳过每个文本文件的第1行?

使用下面的代码,我可以打开我的文件夹中的所有文本文件到一个Excel表。 每个文件都有标题,而我无法弄清楚是如何让它跳过每个文本文件的第一行。

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("\\mydirectoryfolderhere") ' 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 For i = 0 To UBound(Items) cl.Offset(1, i).Value = Items(i) Next '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 

像这样(未经testing)

 Dim firstline as boolean '..... For Each file In folder.Files Set FileText = file.OpenAsTextStream(ForReading) firstline=True Do While Not FileText.AtEndOfStream TextLine = FileText.ReadLine If Not firstline then Items = Split(TextLine, "|") For i = 0 To UBound(Items) cl.Offset(1, i).Value = Items(i) Next Set cl = cl.Offset(1, 0) End If firstline=False Loop ' Clean up FileText.Close Next file '....