Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Edit csv text file with VBA

Edit the filename and header information as per your requirement....

Sub WriteHeaderToCSV()

Dim strFile As String
Dim varData As Variant
Dim fso, f

strFile = "c:\test.csv"
strHeader = "Col1,col2,col3"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(strFile, 1)
varData = f.ReadAll
f.Close
fso.DeleteFile strFile, True

Set f = fso.OpenTextFile(strFile, ForWriting, True)
f.Write strHeader & vbCrLf
f.Write varData
f.Close

End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"sJ" wrote:


I receive a csv text file in Excel that I need to change the first row of
data in. Doing this in Excel and saving the file converts numbers such as
000200 to 200 etc. Is there a way to do this with the VBA Open and Print
statements?




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
Importing text file, only option to edit existing file smokey99 Excel Discussion (Misc queries) 8 April 26th 06 09:08 PM
2 users open same file and both can edit/change the file RANDY Excel Discussion (Misc queries) 1 January 24th 06 04:06 PM
Use XL 2 Edit a .txt File? Matthew =}[_2_] Excel Programming 5 April 19th 04 06:17 PM
Use XL 2 Edit a .txt file? Matthew =} Excel Programming 0 April 16th 04 06:24 PM
Can I edit .iqy file from code? Nathan Gutman Excel Programming 2 December 18th 03 08:29 PM


All times are GMT +1. The time now is 11:16 AM.

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"