Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Insert line in first row of CSV text file with VBA

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatentate text and insert blank line Bethany Excel Worksheet Functions 5 November 10th 09 06:38 PM
Reading a text file line by line stressman Excel Programming 3 October 16th 05 05:29 AM
H2 insert a text tag into a line graph Colin Chisholm Charts and Charting in Excel 2 October 9th 05 01:14 PM
Reading a text file line by line Foss[_2_] Excel Programming 4 March 16th 05 04:01 PM
import huge text file line-by-line? rachel Excel Programming 2 November 6th 04 04:43 PM


All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"