Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Remove a line from a text file
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Remove a line from a text file
Thanks I give it a try.
Regards "DomThePom" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Remove headers from text file | Excel Discussion (Misc queries) | |||
remove line breaks in text strings | New Users to Excel | |||
Reading a text file line by line | Excel Programming | |||
Reading a text file line by line | Excel Programming | |||
import huge text file line-by-line? | Excel Programming |