View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default vba code to replace first row in CSV file


If you are putting the data on a spreadsheet before making your revisions
you will get exactly the result you state here. It would be better to read
the file into a string variable and replace the first line with the data you
want to insert, then write the file back.

This will require parsing the first line in a For Each... Next loop using
the Split() function and specifying vbCrLf as the delimiter. Once you have
the first line loaded into a variable you could use the Replace() function to
swap it with your new first line.

HTH
Kind regards, Garry
"JP" wrote:

I receive CSV files that I need to open and replace the first row of data
with different column headings and close and save the file.

When I do this in Excel and save it, it truncates data below the first row
that begins with 0. For example, 000300 is saved as 300.

Is there a way to do this with the Open and Print statements in VBA?