Save .CSV file as .txt without opening

QuantBurner

New Member
Joined
Jan 29, 2011
Messages
42
Hi!
I download .csv files with CUSIPs. The cusips are nine characters and sometimes have leading zeroes or are sometimes a combination of numbers and "e". If I open the file, Excel drops the leading zeroes and interprets the e as scientific notation. However, if I open the .CSV file in word and save it as a .TXT file, I can then specify that the column with CUSIPS is text when I open it in Excel. Hence, why I'd like to save the .CSV file as a .TXT file without opening it using some VBA code.
Thanks!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
you can import a CSV from the DATA tab, and then choose TEXT format for the CUSIP column


MsVVJX1.png


then on the 3rd step, choose text for the CUSIP column

kzKZxNK.png


I5A7c6N
 
Upvote 0
What version of Excel is that?
I got the VBA code I needed to do your operation via the "record macro." It works like a champ.
Thanks!!!
 
Upvote 0
Well... I thought it would be easy to take the macro I recorded to get the VBA for the query and then add some VBA code before the query creation to have the user browse to select the file. But that's not working. I get "application-defined or object-defined" error. I would have thought I could capture the file path as a string via msoFileDialogOpen and plug that string into the activeworkbook.Queries.add function and OLEDB;Provider......
Suggestions?
 
Upvote 0
you can import a CSV from the DATA tab, and then choose TEXT format for the CUSIP column
then on the 3rd step, choose text for the CUSIP column

I5A7c6N

Since Excel 1995 or earlier.
Excel 2016 provides a better tool for data imports, see Get & Transform.
 
Upvote 0
I monkeyed with the VBA a bit and am now getting a "The import strCSVTest matches no exports. Did you miss a module reference?" Error.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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