Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a fixed text file into a csv file

Status
Not open for further replies.

cassandra

Programmer
Oct 10, 2000
21
US
Can anyone point me in the right direction on how I can save a text file into a cvs file from VB.

Thanks for your help.

Cassandra
 
Its a little long, but here is one way:

Copy this into a module:
Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

In your form call:
Dim sFilePath as string
dim sNewFile as string

sfilepath = 'path and file name of .txt file
snewFile = Replace(sfilepath,"txt", "csv")
apiCopyFile sfilepath ,sNewFile, False
'delete file from current directory
Kill sfilepath
 
Woyler,

Great job! One more question. My text file is a fixed file, now is there a way I can tweak it in VB instead of using Excel file import wizard?

Thanks
 
If you know the spacing definition. You can open the file,
write the values in to variables, format them how ever you need to, and write the output to your new .cvs file.
 
Woyler
All I needed is another brain....Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top