View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Open csv file with all values as text

Change the extension to .txt instead of .csv and then open it in excel. Walk
through the text import wizard with the macro recorder turn on.

In the last dialog indicate which columns should be treated as text.

complete the import and turn off the macro recorder.

In your code, add code at the top to copy the file and rename the copy with
a .txt extension. Then open that (and delete it later if necessary).


Even with recorded code, it you open a file with a .csv extention, your
settings will be ignored.

--
Regards,
Tom Ogilvy


"bony_tony" wrote:

Hi,
When excel opens my csv file, the numbers in it are automatically
changed to actual numbers, when I want them displayed as text/strings.

The problem with this is that, i.e my string "00500" is changed to the
value 500 when the file is opened, and will remain as 500 when the
file is saved again.

Does someone have some code which will prompt the user to select a csv
file, then open the file with all values as text/strings??

Cheers
Tony