我想连接几个以完全相同的方式构建的文本文件,但是我想保留第一行的第一行并删除连续20多个文件的标题行。 到目前为止,我已经能够通过使用以下脚本连接,但我不知道如何避免第一行。
Sub snb() 'This Macro opens all .txt files in a given path and concatenates them
c00 = "C:\some path" ' the path
c01 = Dir(c00 & "*.txt")
Location = "destination_path\" 'Here is where the combined file will be
DateStamp = CStr(Year(Date)) & CStr(Month(Date)) & CStr(Day(Date))
x = 0
Do Until c01 = ""
If x = 0 Then
c02 = c02 & CreateObject("scripting.filesystemobject").opentextfile(c00 & c01).readall
c01 = Dir
x = 1
Else
c02 = c02 & vbCrLf & CreateObject("scripting.filesystemobject").opentextfile(c00 & c01).readall '
c01 = Dir
End If
Loop
CreateObject("scripting.filesystemobject").createtextfile(Location & DateStamp & "_new.txt").write c02
End Sub
答案 0 :(得分:0)
以下是If
语句的外观:
If x = 0 Then
c02 = c02 & CreateObject("scripting.filesystemobject").opentextfile(c00 & c01).readall
c01 = Dir
x = 1
Else
fs = CreateObject("Scripting.filesystemobject").opentextfile(c00 & c01).readall
toRemove = InStr(fs, vbCrLf) + 1
fs = Right(CStr(fs), Len(fs) - toRemove)
c02 = c02 & vbCrLf & fs
c01 = Dir
End If
这是做什么的: