Open CSV as txt data

M

Moderate

I need to open a CSV file in Excel that contains numbers with leading zeros.
Excel truncates leading zeros. How can I open a CSV file with the cells
defined as txt so that the leading zeros are not truncated?

Thanks,
 
P

Pete_UK

Rename the file to .txt rather than .csv. Then when you use File |
Open (or Button | Open) in Excel and point to that .txt file you will
be taken automatically into the Data Import Wizard. On the third panel
of this you can highlight each column in turn and specify how you want
that data to be treated (i.e. Text in your example).

Hope this helps.

Pete
 
M

Moderate

Thanks Pete, I was hoping for something a little quicker, I have a lot of
these files.

Rename the file to .txt rather than .csv. Then when you use File |
Open (or Button | Open) in Excel and point to that .txt file you will
be taken automatically into the Data Import Wizard. On the third panel
of this you can highlight each column in turn and specify how you want
that data to be treated (i.e. Text in your example).

Hope this helps.

Pete
 
P

Pete_UK

Well, what is the onerous part - renaming the file or going through
the Text Import Wizard?

If you want to avoid renaming the file, you can click the Data tab,
then in the Get External Data section (XL2007 menus) click on From
Text, then navigate to and identify the file that you want, and this
will take you into the Text Import Wizard, and you can use this as
described before.

If you start to record a macro before you do this and then stop
recording when you have imported the data, then you should be able to
edit the macro to allow you to select the file each time it is run
(and perhaps save it at the end with a name derived from the original
file). Then in future you can just run the macro, select the file and
it will be imported as you would like it, then saved.

Hope this helps.

Pete
 
M

Moderate

Good idea. Thanks.

Well, what is the onerous part - renaming the file or going through
the Text Import Wizard?

If you want to avoid renaming the file, you can click the Data tab,
then in the Get External Data section (XL2007 menus) click on From
Text, then navigate to and identify the file that you want, and this
will take you into the Text Import Wizard, and you can use this as
described before.

If you start to record a macro before you do this and then stop
recording when you have imported the data, then you should be able to
edit the macro to allow you to select the file each time it is run
(and perhaps save it at the end with a name derived from the original
file). Then in future you can just run the macro, select the file and
it will be imported as you would like it, then saved.

Hope this helps.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top