View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
DomThePom DomThePom is offline
external usenet poster
 
Posts: 54
Default Remove a line from a text file

You have to create a new text file with the line no longer requirted removed

This is some code to remove a file header:

Function RemoveHeader(ByVal strOldFileName As String, _
ByVal strNewFileName As String) As Variant

'function removes header from strOldFileName
'creating strNewFileName and returning an array of the record count
and the removed header


Dim strLineOld As String 'Current line
Dim hFileOld As Long 'Handle on old file
Dim hFileNew As Long 'Handle on new file
Dim intI As Integer 'Counter
Dim strHeader As String 'header removed
Dim lngLineCountOld As Long 'recordcounter

'set up error handler
On Error GoTo ProcError

'get file handles
hFileOld = FreeFile
hFileNew = FreeFile + 1

'open up files
Open strNewFileName For Output As hFileNew
Open strOldFileName For Input As hFileOld

'get header from first line
Line Input #hFileOld, strLineOld
strHeader = strLineOld


Do Until EOF(hFileOld)
'get the next line of old file
'and write it to new file
Line Input #hFileOld, strLineOld
lngLineCountOld = lngLineCountOld + 1
Print #hFileNew, strLineOld
Loop
RemoveHeader = Array(lngLineCountOld, strHeader)

ProcExit:
'close files
Close hFileOld
Close hFileNew
DoCmd.Echo True
Exit Function
ProcError:
DoCmd.Echo True
MsgBox Error(Err)

Resume ProcExit


End Function

"vqthomf" wrote:

I use a text file to hold information but I need to be able remove a line of
data, I was wondering if this is possible I have tried to inforamtion on this
without success.
Can any body please help.
TIA
Charles