Converting txt files to CSV files

ANONYMOUS123456

Board Regular
Joined
Jul 3, 2016
Messages
85
Hi everyone,
I have 1000 txt files. Each txt file contains an article. I want to convert all of them to CSV files and the data of each txt file should stay in A1 cell of corresponding output CSV file.

I have once tried to convert txt files to CSV files but the data is splitted into multiple cells of resulted csv file which is what I don't want.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
A CSV file is a text file already, just formatted with commas.
Not sure what you're trying to accomplish as I can't understand your problem description.
 
Upvote 0
A CSV file is a text file already, just formatted with commas.
Not sure what you're trying to accomplish as I can't understand your problem description.

Actually My end object is to import all the text file to an excel sheet. I have a VBA code which imports CSV files to an excel sheet but the data should reside in A1 cell of all CSV files before importing. But in my case when I convert text files to CSV files then the data is splitted into multiple columns which is the only problem and VBA code is not working on such CSV files. For reference, I VBA code is given below:


Option Explicit


Sub ImportCSVsWithReference()
'Author: Jerry
'Date: 10/16/2010
' Import all CSV files from a folder into a single sheet
' adding a field in column A listing the CSV filenames


Dim wbCSV As Workbook
Dim wsMstr As Worksheet: Set wsMstr = ThisWorkbook.Sheets("MasterCSV")
Dim fPath As String: fPath = "C:\Import\" 'path to CSV files, include the final \
Dim fCSV As String


Application.ScreenUpdating = False


fCSV = Dir(fPath & "*.csv") 'start the CSV file listing


Do While Len(fCSV) > 0
'open a CSV file
Set wbCSV = Workbooks.Open(fPath & fCSV)
'insert col A and add CSV name
Columns(1).Insert xlShiftToRight
Columns(1).SpecialCells(xlBlanks).Value = ActiveSheet.Name
'copy date into master sheet and close source file
ActiveSheet.UsedRange.Copy wsMstr.Range("A" & Rows.Count).End(xlUp).Offset(1)
wbCSV.Close False
'ready next CSV
fCSV = Dir
Loop

Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top