How to change file extension using VBA

  • Thread starter Thread starter Kate
  • Start date Start date
K

Kate

Hi,

I am trying to open a CSV file using VBA, and after reading a few
other posts is appears that it is a common problem that dates are
interpreted incorrectly when opening CSV files using VBA, and that a
solution ot this problem is to convert the file to a TXT extension.

How would I go about changing the file extension of a file from CSV to
TXT using VBA from within Excel? I do not want the user to have to do
this manually, I want to do this all using code within Excel.

Thanks in anticipation
 
A quick answer would be to use
FileCopy SourceFileName, DestinationFileName

However, you should not have any problems opening the file if you ar
using VBA. Look up VB Editor Help for the OpenText Method.

Perhaps quicker, rename your .csv file to .txt and set to record
macro before opening the file. You will see that you then get th
wizard with options including the facility to set the data type fo
each field. All you need to do then is to change the .txt file suffi
in the code to .csv to automate the whole process for the future
 
Kate,

Look at the Name statement in VBA. Type Name in a sub, and press F1.

When you open a file with a txt extension, you are prompted with the text
import wizard, where you can specify date formats. I'm not sure this will
help with interpreting dates though. You should try one opening manually
before you write code.

Which release of Excel?
 
Back
Top