View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Charlotte E.[_3_] Charlotte E.[_3_] is offline
external usenet poster
 
Posts: 160
Default Delete all, but the last 23 lines of an external text file

Bingo!
Working :-)

Thanks, Harald :-)


CE



"Harald Staff" wrote in message
...
Hi Charlotte

One way, simplified to three lines and without a saving procedu

Sub test()
Dim iFnum As Integer
Dim Linje As String
Dim S1 As String, S2 As String, S3 As String
iFnum = FreeFile
Open "C:\Temp\Test.txt" For Input As #iFnum
While Not EOF(iFnum)
Line Input #iFnum, Linje
S1 = S2
S2 = S3
S3 = Linje
Wend
Close #iFnum
' save to original file instead of
MsgBox S1 & vbNewLine & S2 & vbNewLine & S3
End Sub

Beste hilsen Harald


"Charlotte E." skrev i melding
...
Hi Guys,


I have a workbook that write a new line to an external (text file) log
each day.
This works fine no problem here...

But we really only need to be able to view the lines for the past month -
in fact even only the last 23 lines in the log file, since there are
never more than 23 workdays in a month.

So, how to delete all but the last 23 rows in an external text files,
using VBA?


TIA,

CE