Solved Open a txt File remove the first line and save

Number11

Member
Local time
Today, 12:28
Joined
Jan 29, 2020
Messages
619
Looking some some code to open a text file remove the first line and the save the txt file
 
Code:
Private Sub t()
Dim content As String
Dim var As Variant
Dim path As String

'put the path and filename of textfile here
path = Environ$("userprofile") & "\desktop\t.txt"

With CreateObject("Scripting.FileSystemObject")
    With .opentextfile(path, 1)
        content = .ReadAll
        .Close
    End With
    var = Split(content, vbCrLf)
    For i = 1 To UBound(var)
        var(i - 1) = var(i)
    Next
    ReDim Preserve var(UBound(var) - 1)
    content = Join(var, vbCrLf)
    With .opentextfile(path, 2)
        .Write content
        .Close
    End With
End With
    
End Sub
 
Somewhat shortened:
Code:
...
    var = Split(content, vbCrLf, 2)
...
    content = var(1)
...
 

Users who are viewing this thread

Back
Top Bottom