Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
how do i convert text files into CSV files?
|
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
convert files to text | Excel Discussion (Misc queries) | |||
converter tool to convert XL 2007 files to XL 2003 files | Excel Discussion (Misc queries) | |||
how to convert .dat files to .idx files | Excel Discussion (Misc queries) | |||
Can I convert my Quatro Pro files to MS Excel files? | New Users to Excel | |||
How do I import/convert tab delimited text files into Excel? | Excel Worksheet Functions |