Create CSV as TXT file

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,223
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Hey All

I'm trying to use VBA in Excel 2003 to export a file as a CSV but with a TXT file extension.

So after some messing about I came to the conclusion that the best idea would be to create the CSV file as I normally would do and then simply rename the ".csv" as ".txt" which I can do no problem in DOS but I'd like to finish the job properly in the Macro.

Only problem being I don't have a clue how to do that from within VBA :(

Ideally if someone could point me in the right direction of the VBA equivalent of the DOS
Code:
ren *.csv *.txt
that would be great :)

Thanks in advance for any help that can be provided.
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
You are looking for the Name statement ie:

Code:
Name Fullname&Path As NewFullName&Path

'eg:

Name "C:\SomeFolder\myTextFile.csv" As "C:\SomeFolder\myTextFile.txt"

EDIT: If you have more than one file, you need to loop thru the files doing each one individually.
 

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,223
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Ha! - So simple when you put it like that Richard!

I'd got NO idea that 'Name' existed LOL

Thanks a lot for the quick reply :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,721
Messages
5,597,752
Members
414,171
Latest member
12Rev79

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
Top