View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Insert line in first row of CSV text file with VBA

Try this code:

Sub InsertLineAtBeginningTexFile(strFile As String, strLine As String)

Dim hFile As Long
Dim FileContents As String
Dim NewString As String

hFile = FreeFile
Open strFile For Binary As #hFile
FileContents = Space(FileLen(strFile))
Get #hFile, , FileContents
Close #hFile

NewString = strLine & vbCrLf
FileContents = NewString & FileContents

Open strFile For Binary As #hFile
Put #hFile, , FileContents
Close #hFile

End Sub


RBS


"JA" wrote in message
...
I have a CSV text file and would like to insert a row at the top using the
VBA Write statement from Excel. I am able to append, but can not add to
the first line.