在Excel中导入csv文件后删除多个标头

我需要将数百个具有相同格式的CSV文件合并到一个文件中,而不必使用excel makro重复头文件。 我可以使用以下代码select要导入的文件(并将其导入):

Dim dateien, i, lastrow lastrow = 1 dateien = Application.GetOpenFilename _ ("csv-Dateien (*.csv), *.csv", MultiSelect:=True) If IsArray(dateien) Then For i = 1 To UBound(dateien) Workbooks.Open dateien(i), local:=True With ThisWorkbook.Sheets(1) ActiveSheet.UsedRange.Copy Destination:=.Range("A" & lastrow) lastrow = .UsedRange.Rows.Count + 1 End With ActiveWorkbook.Close False Next i End If 

不过,我真的不知道如何删除重复的标题…

我会采取打开FileSystemObject每个文件的方法,读取其中的所有数据,然后发射出来没有自己的标题:

 Dim dateien, i, lastrow lastrow = 1 dateien = Application.GetOpenFilename _ ("csv-Dateien (*.csv), *.csv", MultiSelect:=True) dim oFso : Set oFso = CreateObject("Scripting.FileSystemObject") Dim oSourceFile, oTargetFile Set oTargetFile = oFso.CreateTextFile("pathtofilehere", True) Dim sArray() If IsArray(dateien) Then For i = 1 To UBound(dateien) ' Arrays in VBA index from zero, not 1 - you're skipping the first element in dateien ReDim sArray(0) Set oSourceFile = oFso.OpenTextFile(dateien(i), 1) ' open for reading While Not oSourceFile.AtEndOfStream ' while there is data in the file sArray(Ubound(sArray)) = oSourceFile.ReadLine ' add the line to an array ReDim Preserve sArray(UBound(sArray)+1) ' increase size of the array by 1 Wend ' Now we have the whole file in an array For myLoop = 1 to UBound(sArray) ' Loop from 1 and we skip the header line in the file oTargetFile.WriteLine sArray(myLoop) ' write array values into file Next myLoop ' repeat for each line in the array Next i ' repeat for each file in dateien End If