paolo.libero
09-21-2020, 11:19 AM
Hi to all, i'm a newbie into VBA coding, and i'm unexperienced, i'd be really glad and i'd appreciate if someone could help me,
I'm creating a Vba that should open a txt file, read it and write it back excluding the last line (since apparently there's no way to delete directly last line)
i'll past what i'm using, i keep having a run time error, and also an error that asks me to define the object, am i missing something?
Sub Deletes_Last_Line()
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile("C:\Users\final\Desktop\wiki.txt", ForReading)
strContents = objFile.ReadAll
objFile.Close
arrLines = Split(strContents, vbCrLf)
Set objFile = objFSO.OpenTextFile("C:\Users\final\Desktop\wiki.txt", ForWriting)
lines.RemoveAt (lines.Count - 1)
objFile.WriteLine arrLines(i)
objFile.Close
End Sub
I'm creating a Vba that should open a txt file, read it and write it back excluding the last line (since apparently there's no way to delete directly last line)
i'll past what i'm using, i keep having a run time error, and also an error that asks me to define the object, am i missing something?
Sub Deletes_Last_Line()
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile("C:\Users\final\Desktop\wiki.txt", ForReading)
strContents = objFile.ReadAll
objFile.Close
arrLines = Split(strContents, vbCrLf)
Set objFile = objFSO.OpenTextFile("C:\Users\final\Desktop\wiki.txt", ForWriting)
lines.RemoveAt (lines.Count - 1)
objFile.WriteLine arrLines(i)
objFile.Close
End Sub