Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default how do i convert text files into CSV files?


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,651
Default how do i convert text files into CSV files?

If your fields are separated by commas, then it already is a CSV. Take a
copy and rename as CSV if you wish.

If your fields are separated in some either way, either by tabs or other
characters, or by the use of fixed width fields, then opening the txt file
from within Excel will give you a wizard to select the fields accordingly,
and to choose a format for the columns as you import them. Having read the
data into Excel, you can save as CSV if you wish, but remember that reading
a CSV into Excel directly doesn't give you the flexibility that the wizard
gives, so if in doubt rename to .TXT instead of .CSV before you read it into
Excel.

[... and next time, please ask your question in the body of the message, not
just in the subject line.]
--
David Biddulph

"airpr23" wrote in message
...



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default how do i convert text files into CSV files?

It depends on the format of the text files. Do they have a delimiter? You
could use the Text Import Wizard by choosing "Text Files" in the Get
External Data dialog from the Data menu and the do a Save As to CSV.

Or you could write code to bypass Excel altogether.

Sub ConvertTextToCSV(InputFileName As String, _
OutputFileName As String, _
Delimiter As String)

Dim InFNum As Integer
Dim OutFNum As Integer
Dim InputLine As String
Dim RecCount As Long

InFNum = FreeFile()
Open InputFileName For Input Access Read As #InFNum
OutFNum = FreeFile()
Open OutputFileName For Output Access Write As #OutFNum
Do
Line Input #InFNum, InputLine
RecCount = RecCount + 1
InputLine = Replace(InputLine, Delimiter, ",", , , vbBinaryCompare)
Print #OutFNum, InputLine
Loop Until EOF(InFNum)

Close #InFNum
Close #OutFNum

Debug.Print "Records: " & CStr(RecCount)

End Sub

Sub Test()
ConvertTextToCSV InputFileName:="C:\Test.txt", _
OutputFileName:="C:\Test.csv", _
Delimiter:=" "

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"airpr23" wrote in message
...



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
convert files to text Jason Excel Discussion (Misc queries) 1 January 17th 07 06:53 AM
converter tool to convert XL 2007 files to XL 2003 files Dave F Excel Discussion (Misc queries) 6 December 15th 06 12:45 AM
how to convert .dat files to .idx files Isss Excel Discussion (Misc queries) 0 June 23rd 06 07:21 PM
Can I convert my Quatro Pro files to MS Excel files? James HW New Users to Excel 3 May 11th 06 04:42 PM
How do I import/convert tab delimited text files into Excel? jim Excel Worksheet Functions 10 May 3rd 05 10:46 PM


All times are GMT +1. The time now is 03:22 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"